Solved

Using VB with an Access database

Posted on 1998-09-27
10
382 Views
Last Modified: 2008-03-10
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?
0
Comment
Question by:treyjeff
10 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1436874
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.

M


0
 
LVL 1

Expert Comment

by:toys032498
ID: 1436875
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,
Anthony
0
 
LVL 1

Author Comment

by:treyjeff
ID: 1436876
What is ADO, I'm using VB 5.0 Pro by the way and Access 95.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:treyjeff
ID: 1436877
I got an error on the following line:
Set db = DBEngine.Workspaces(0).OpenDatabase(DataDir)
It said unable to open the DLL.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1436878
treyjeff:
Can you state the exact error message.
"unable to open the DLL" is not found in the error list.
0
 
LVL 1

Author Comment

by:treyjeff
ID: 1436879
Run time error 48
Error in loading DLL
0
 
LVL 2

Expert Comment

by:shogi
ID: 1436880
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.

Regards,
Shogi
0
 
LVL 1

Accepted Solution

by:
toys032498 earned 40 total points
ID: 1436881
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.
Anthony
0
 
LVL 1

Author Comment

by:treyjeff
ID: 1436882
Thanks, i had it referenced all along but I also had a reference to Access and it must have been conflicting.
0
 
LVL 1

Expert Comment

by:toys032498
ID: 1436883
Thanks for the points!
Yeh! That will cause your error.
Good Luck on your Hockey Team Wins. Go Hurricanes....and George too!  Hehehe!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question