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!

opening access from VB

Status
Not open for further replies.

daz321

Programmer
May 31, 2002
17
GB
I am trying to open access from VB, as i need to run some queries/macros to manipulate the data before i use it within VB. I am using the following code to test open the database.

Private Sub Form_Load()
Dim LetterType As String
Dim AccessApp As Access.Application
Dim DBPath As String

DBPath = "C:\My Documents\darryl.mdb"
Set AccessApp = New Access.Application
With AccessApp
.openCurrentDatabase DBPath
.DoCmd.OpenTable "R01"
End With
AccessApp.quit

However it doesn't seem to like the
Dim AccessApp as Access.Application
line. I comes back with a user type not defined error.

 
Did you add the reference to the Access Object Library? Anything is possible, the problem is I only have one lifetime.
[cheers]
 
[smarty] You must either add a reference to MS-Access (like foada suggested) or use the createObject function. The reference is created with the project -> references menu. If the autocomplete works for MS-Access objects, the reference is working.

Best regards
 
i have added the access object library and the error has gone, but the database isn't opening. i think the code is correct but i could (and have been) be wrong

Dim AccessApp As Access.Application
Dim DBPath As String

DBPath = "C:\My Documents\darryl.mdb"
Set AccessApp = New Access.Application
With AccessApp
.openCurrentDatabase DBPath
.DoCmd.OpenTable "R01"
End With
 
Perhaps try making the AccessApp visible....??? I've opened Access reports and discovered that I needed to make the access object visible to see the reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top