Solved

VB6: Opening a .mdb file for modifications and updates

Posted on 2000-04-02
7
435 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

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

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now