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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open a access database

Status
Not open for further replies.

Zeroanarchy

Technical User
Jun 11, 2001
630
0
0
AU
I have not got a lot of experience with VB and I am looking for a way to open an access database.

I have tried
Dim RetVal
RetVal = Shell("c:\program files\access.exe, mydatabase.mdb", 1)

the problem with shell is if they have placed access somewhere else it will not work.

so I tried

Private Sub sampleLabel_Click(Index As Integer)
Dim db As Database
Set db = DBEngine.OpenDatabase("C:\mydatabase.mdb")
End Sub

and I get an error

compile error
User-defined type not defined

All I want it to do is run the database.

Thanks Zero
 
You can try this way:

Private Sub sampleLabel_Click(Index As Integer)
Dim TestAs New ADODB.Connection
Test.ConnectionString="Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source=C:\AAA\Tables.mdb;"

Test.Open

End Sub

Please do not forget selecting ADO2.50 in Reference.
 
Zcjl thanks for your help just a quick query.


There seems to be an error with this line, its highlited red.

Dim TestAs New ADODB.Connection

as for the reference,are you refereing to;
Microsoft DAO 2.5/3.5 compatibiltity Library.

Thanks Zero
 
Hi!

The error is actually a typing mistake!

Dim TestAs New ADODB.Connection should be
Dim Test As New ADODB.Connection

I would however encourage you to use your first method because DAO is much faster with Access than ADO, but you have to modify it a bit: Just add DAO 3.51 or 3.6 to you References, then type:

Dim db As Database
Set db = OpenDatabase("C:\mydatabase.mdb")

Then you can do just about anything with your db. You can also declare another variable As TableDef and then open a table. It's all in VB's help.

Aleksander
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top