Solved

VB6: Opening a .mdb file for modifications and updates

Posted on 2000-04-02
7
441 Views
Last Modified: 2009-12-16
Hello all,

I am fairly new to the world of VB, and i am trying to get my program to open a .mdb file for editing.
I did a full install of visual studio, however i get a:
"Sub or Function not defined" error on
Set dbTest = OpenDatabase("c:\database.mdb")

This is the function I see used in all examples of accessing .mdb files, is there something im doing wrong?

Thanks!

:Jason
0
Comment
Question by:Figment060799
[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
7 Comments
 
LVL 2

Accepted Solution

by:
arikka earned 100 total points
ID: 2678111
OpenDatabase is method of Microsft DAO
Opens a specified database in a Workspace object and returns a reference to the Database object that represents it. You should call this method on Workspace object.

Instead
Set dbTest = OpenDatabase("c:\database.mdb")
Should be

Dim wrkJet As Workspace
Dim dbsMyBd As Database
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set dbsMyBd = wrkJet.OpenDatabase("c:\database.mdb", _
      True)

See below full example :

Sub OpenDatabaseX()

   Dim wrkJet As Workspace
   Dim dbsNorthwind As Database
   Dim dbsPubs As Database
   Dim dbsPubs2 As Database
   Dim dbsLoop As Database
   Dim prpLoop As Property

   ' Create Microsoft Jet Workspace object.
   Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

   ' Open Database object from saved Microsoft Jet database
   ' for exclusive use.
   MsgBox "Opening Northwind..."
   Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb", _
      True)

   ' Open read-only Database object based on information in
   ' the connect string.
   MsgBox "Opening pubs..."
   Set dbsPubs = wrkJet.OpenDatabase("Publishers", _
      dbDriverNoPrompt, True, _
      "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")

end Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2678112
did you declare it first??
Dim dbTest As Database
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2678118
you should be able to just use

Dim db As Database
Set db = OpenDatabase("c:\database.mdb")

Thats what i always do and it works fine
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 28

Expert Comment

by:AzraSound
ID: 2678183
There is a Reference you set under the Projects menu item that allows you to just do as I stated.  When I get home I will look and see what that reference is
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2678221
Helping Azra (who beat me to the answer.. <groan>):

From the Vb Menu:
1. Click On Projects
2. Click On References
3. Check "Microsoft DAO 3.51 Object Library"
4. Click On Ok
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2680576
Either do as wsh2 says or simply drop a data control on your form to let the compiler know to include the database stuff. Make the control invisible and you're done.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2682436
figment: pardon me for going offthread for a second.. k?

mark2150:
Hi Mark.. <smile>.
<Now digging an old skeleton out of the closet.. <wink>>. I thought of you the other day while perusing MSDN. If you get a chance.. checkout MSDN keyword "DiskProbe" (a MS subpackaged utility on an install cdrom somewhere.. <sheesh>).. its a partition table / FAT / Disk Sector display program that will remind you of the good ole DOS 3 Norton Disk Doctor days.. <lol>. Now get this.. ion the writeup of the utility.. it said it supported Win / NT.. and even NTFS. I saw that.. and couldn't help but pass that along to you. Check it out if / when you get the time.. <smile>.
0

Featured Post

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!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

696 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