?
Solved

VB6: Opening a .mdb file for modifications and updates

Posted on 2000-04-02
7
Medium Priority
?
442 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 300 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
Technology Partners: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

752 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