Link to home
Start Free TrialLog in
Avatar of schler
schler

asked on

Compiling ACCESS in a VB application

Is there any possiblity to insert an access DB to a VB application, and generate an exe file, that will run on computers that have no MS-ACCESS installed? What is the best way to use the DB in the VB application?
ASKER CERTIFIED SOLUTION
Avatar of jjbyers
jjbyers

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mark2150
mark2150

You can even have your VB program create a .MDB on the fly. Access is *NOT* required on the target system. Here's some code:

Text1(2).Text is a control that has the drive:\path\ of the MDB file, REFMDB has the file name with the .MDB extension

db is PUBLIC ... AS DATABASE

'
' Crank up data engine to create database
'
Set db = DBEngine.Workspaces(0).CreateDatabase(Text1(2).Text & "\" & refmdb, dbLangGeneral)
Set tbl = db.CreateTableDef("Results")  'Configuration
'
' Filename - C20
' DiskVol  - C11
' Pagenum  - N3
' DateTime - Date/Time
' Client   - N6
' Debtor   - N6
'
Set fld = tbl.CreateField("Filename", dbText, 20)
fld.AllowZeroLength = True
tbl.Fields.Append fld
'
Set fld = tbl.CreateField("DiskVol", dbText, 11)
fld.AllowZeroLength = True
tbl.Fields.Append fld
'
Set fld = tbl.CreateField("Pagenum", dbInteger)
tbl.Fields.Append fld
'
Set fld = tbl.CreateField("DateTime", dbDate)
tbl.Fields.Append fld
'
Set fld = tbl.CreateField("Client", dbLong)
tbl.Fields.Append fld
'
Set fld = tbl.CreateField("Debtor", dbLong)
tbl.Fields.Append fld
'
Set ndx = tbl.CreateIndex("Key")
ndx.Fields.Append ndx.CreateField("Client")
ndx.Fields.Append ndx.CreateField("Debtor")
ndx.Unique = False
tbl.Indexes.Append ndx
'
Set ndx = tbl.CreateIndex("Location")
ndx.Fields.Append ndx.CreateField("FileName")
ndx.Fields.Append ndx.CreateField("PageNum")
ndx.Unique = False
tbl.Indexes.Append ndx
'
' Commit definition to master dataset
'
db.TableDefs.Append tbl
db.Close

P.S.

You *MUST* put a data control onto your form to let the compiler know to include the JET ISAM. I make the controls .Visible property = FALSE so it doesn't show. The control is *NOT* referenced anywhere in my code, but if you forget the empty control *NONE* of the code will work - very frustrating when I first had to figure *that* out.

M

They've got it right.  You don't include ACCESS with the VB application.  The database is independant of ACCESS.  An ACCESS Database is ODBC compliant, and is accessed by VB through the Jet DB.  If you want to work with databases with out putting a data control on your form, in the Project References, select the Microsoft DAO 3.5 object library.