Solved

VB6: Opening a .mdb file for modifications and updates

Posted on 2000-04-02
7
437 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

778 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