Solved

VB6: Opening a .mdb file for modifications and updates

Posted on 2000-04-02
7
439 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
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
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.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…
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…

828 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