Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Access to VB project

Status
Not open for further replies.

ghost807

IS-IT--Management
Jun 27, 2003
99
US
i have a access front end database that i would like to convert to a VB project but i don't seem to be able to get it to work. i am using access 2000 and VB6

the first question is it even possible to do.
the second is that the VB that i have used in access does seem to work in VB (doCmd seems to be the biggest issue) are there major differences in the coding

i'm not sure what else i need to do to make this work.
the database connection seems to be a major problem. i have it set up connect to the data database but everytime i try to do anything VB tells me that it is an unrecognized data format.
Any help would be greatly appreciated.
Dave
 
Try this: cut and paste my code in the FAQ section of this forum, (substituting your db/table/field names of course!) and it should work. "ADO Basics ..."

--Bill
One may not reach the dawn save by the path of the night
--Kahlil Gibran
 
Actually i have been doing that and i seem to be able to get the database connections to work correctly. the problem still seems to be with the terminology from VBA to VB. any thoughts or suggestions there
 
It would help if we could see the code you're using for the connection & recordset objects.

--Bill
One may not reach the dawn save by the path of the night
--Kahlil Gibran
 
If you already know VBA...then you need to learn and get to know what VB-VBA has to offer.

You do this by pressing F2 and inspecting the methods and properties of the VB, and VBA library, then the ADODB library.
Once done, if you already know ACCESS VBA, you should be able to figure out what methods and properties are similar and to substitute with, or what is needed in order to develope and implement a logic that performs the same functionality.
 
Dim db As Database
Dim td As TableDef, TempTd As TableDef
Dim fields(2) As Field, indexfield As Field
Dim dbindex As Index
Dim dbrecordset As Recordset
Private Sub Form_Load()
Dim table1index As Integer
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> &quot;&quot; Then
Set db = DBEngine.Workspaces(0).OpenDatabase(CommonDialog1.FileName)

table1index = 0
While (db.TableDefs(table1index).Attributes And dbSystemObject)
table1index = table1index + 1
Wend

Set dbrecordset = db.OpenRecordset(db.TableDefs(table1index).Name, dbOpenTable)
Set td = db.TableDefs(table1index)

Label1.Caption = dbrecordset.fields(0).Name
' Label2.Caption = dbrecordset.fields(1).Name
Label3.Caption = dbrecordset.Name
Text1.Text = dbrecordset.fields(0)
' Text2.Text = dbrecordset.fields(1)
End If
End Sub

This works to select a database but can't seem to figure out how to select the table i want(master) and then the field i want(MachineNumber)
currently it will load and then ask me to select the database that i want and then go to the first table(alphabetically) and open that and then display the first field in that record.
Hopefully that helps for more information.
 
Sub Get_Data()
Dim Conn as ADODB.Connection 'Connection
Dim Rs as ADODB.Recordset 'Recordset
Dim strQuery As String 'Command

'Set, describe, and open the connection to the database:

Set Conn = New ADODB.Connection
With Conn
.CursorLocation = adUseClient
.ConnectionString= &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _
&quot;Data Source=C:\MyPath\myDatabase.mdb&quot;
.Open
End With

'Set and define your Command:

strQuery = &quot;SELECT AnyFieldsHere FROM tblTableNameHere &quot;

'This query above SELECTS THE TABLE.
'Set, define and open the recordset. You also assign the
'connection and the command that will allow you to retrieve
'the recordset:

Set Rs = New ADODB.Recordset
With Rs
Set .ActiveConnection = Conn
.CursorType = adOpenStatic
.Source = strQuery
.Open
End With
conn.Execute strquery, , adExecuteNoRecords

'Populate your labels and other controls here. Make sure you SET the controls' recordset to the rs you've assigned the query to...

'clean up:

Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
End Sub






--Bill
One may not reach the dawn save by the path of the night
--Kahlil Gibran
 
Well, you could just use DAO to start with.

Looks like it all should work then...

Just use full qualifiers when declaring:

Dim db As DAO.Database
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top