Solved

Using VB with an Access database

Posted on 1998-09-27
10
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

717 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