Rickyyy
asked on
How to connect access database from Visual Basic
Dear Expert,
I would like to know how to make a connection with access database.
Here is the details:
Database location: F:\Program
Database Name: Project.mdb
SInce I am not family with VB but I make a VBA program from access so want to try convert it to VB.
Thanks.
Ricky.
I would like to know how to make a connection with access database.
Here is the details:
Database location: F:\Program
Database Name: Project.mdb
SInce I am not family with VB but I make a VBA program from access so want to try convert it to VB.
Thanks.
Ricky.
ASKER
Compile error:
User-defined type not defined...
Am I wrong??
Private Sub Form_Load()
Dim rst As DAO.Recordset
Dim sPath As String
Dim tblLabor As String
Set sPath = "F:\Program"
Set tblLabor = "project.mdb"
Set rst = DBEngine.Workspaces(0).Ope nDatabase( sPath).Ope nRecordset ("tblLabor ", dbOpenDynaset)
rst.Close
Set rst = Nothing
End Sub
User-defined type not defined...
Am I wrong??
Private Sub Form_Load()
Dim rst As DAO.Recordset
Dim sPath As String
Dim tblLabor As String
Set sPath = "F:\Program"
Set tblLabor = "project.mdb"
Set rst = DBEngine.Workspaces(0).Ope
rst.Close
Set rst = Nothing
End Sub
Be *sure* you have a Reference set to Microsoft DAO 3.xx ... which is *not* the default (ADO is) in a newly created MDB.
Tools>>References ... scroll down the list and select - if it's not there.
mx
Tools>>References ... scroll down the list and select - if it's not there.
mx
ASKER
Done, but why it say
Compile error:
Object required..
Compile error:
Object required..
Done?
Was that Reference not there? And you added it? And now it works?
When References are missing ... all bets are off ... and all sorts of crazy errors can manifest from missing References.
mx
Was that Reference not there? And you added it? And now it works?
When References are missing ... all bets are off ... and all sorts of crazy errors can manifest from missing References.
mx
ASKER
Yes, I added the Reference..
But this time pop-out the other error message..
Compile error:
Object required..
But this time pop-out the other error message..
Compile error:
Object required..
What line of code does the error occur on?
mx
mx
ASKER
Here
Set sPath = "D:\Program"
Set sPath = "D:\Program"
oh ... change
Set sPath = "D:\Program"
to
sPath = "D:\Program"
no Set
mx
Set sPath = "D:\Program"
to
sPath = "D:\Program"
no Set
mx
Same here:
Set tblLabor = "project.mdb"
change to
tblLabor = "project.mdb"
Set tblLabor = "project.mdb"
change to
tblLabor = "project.mdb"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
now is this error....
Run-time error '3051':
The microsoft Jet database engine cannot open the file 'd:\program' it is already opened excludively by another user, or you need permission to view its data...
Thanks....
Run-time error '3051':
The microsoft Jet database engine cannot open the file 'd:\program' it is already opened excludively by another user, or you need permission to view its data...
Thanks....
You need to have 100% FULL permissions on any Folder containing an Access MDB.
Also, I believe I answered the original question - how to connect. This is a different issue. Can you post a new Question - referencing this Q.
mx
Also, I believe I answered the original question - how to connect. This is a different issue. Can you post a new Question - referencing this Q.
mx
Dim rst As DAO.Recordset
Set rst = DBEngine.Workspaces(0).Ope
' code to operate on recordset
rst.Close
Set rst = Nothing
mx