Solved

Using VB with an Access database

Posted on 1998-09-27
10
378 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now