Using VB with an Access database

I am in he middle of writing a fun little program for our hockey team where we can enter the results from our games and the goal scorers etc.  I want to store the data in an Access table but am having trouble setting up the connection.  Here is what I thought I had to use:
Set oldws = DBEngine.Workspaces(0)
Set olddb = oldws.OpenDatabase(Path + "hurricanes.mdb")
Set newdyn = olddb.OpenRecordset("Select * from individual", dbOpenDynaset)
I also have these in a module:
Public olddb As Database
Public oldws As Workspace
Public newdyn As Recordset
For some reason it stops st the set statements, can anyone help me?
Who is Participating?
ADO is ActiveX Data Object, very similar to DAO and RDO
You can download ADO 1.5 from Microsoft as a release version,  VB6.0 has the lastest version 2.0.  Check it out! Its awsome stuff!

Dont forget to Reference you DAO Object like I told ya or you will get the .dll Error.  VB is looking for the refernce to DAO Object and cant find it cause it doesnt exist in your application unil you reference it.
Which statement does it stop at?

This is what I use:

Set db = DBEngine.Workspaces(0).OpenDatabase(DataDir)
Set tbl = db.OpenRecordset("config")

Since I want all records/fields I don't have to use a SELECT, I just open the table and go.

I never close the db object until the program exits. Tables I open and close on demand, but the reset I let stand.


Did you reference the Microsoft DAO 3.5 Object Library before you begin coding?
If so this is all you have to write for accessing an Access Database.

Private Sub Form_Load()

' Create dynaset-type recordsets

Dim db as Database 'The dynaset object
Dim rs as Recordset 'The recordset object

'  Create local variables
Dim strDBname as string
Dim strRSname as string

'  Initialize the variables
strDBname = App.Path & "c:\hurricanes.mdb"
strRSname = "tblName here"

' Create the objects
Set db = DBEngine.OpenDatabase(strDBname)
Set rs = db.OpenRecordset(strRSname, dbOpenDynaset)

End Sub

If you really want to make it easy, why not use ADO?
Good luck,
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

treyjeffAuthor Commented:
What is ADO, I'm using VB 5.0 Pro by the way and Access 95.
treyjeffAuthor Commented:
I got an error on the following line:
Set db = DBEngine.Workspaces(0).OpenDatabase(DataDir)
It said unable to open the DLL.
Can you state the exact error message.
"unable to open the DLL" is not found in the error list.
treyjeffAuthor Commented:
Run time error 48
Error in loading DLL
Check in you reference, do you have the right DAO?

Go in "Project" -> "references"
Selecte "Microsoft DAO 3.5 Object library"

if it's selected you receive again this message : it's because you don't have any more this DLL on you system or your DLL it's not registred in the registry.

treyjeffAuthor Commented:
Thanks, i had it referenced all along but I also had a reference to Access and it must have been conflicting.
Thanks for the points!
Yeh! That will cause your error.
Good Luck on your Hockey Team Wins. Go Hurricanes....and George too!  Hehehe!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.