Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic loading of access db and automatically setting the Connection

Status
Not open for further replies.

rtvillan

Technical User
Joined
Jan 3, 2002
Messages
9
Location
US
I need help or a code on how to dynamically load a new
Access database (db2.mdf) to a program. It loads db1.mdf by default. Also, how do I automatically set the connection string the same as the db1.mdf (connection string name is 'robert'.
The customer at this point clicks on a command that brings up a common dialog box that will enable him to open up the new database (db2.mdf) with tables. Upon pressing "OK" after the creation, I would like it to automatically load the new database. Below is the code i used to create the DB:

sub main()
Dim MyDB as ADOX.Catalog
Dim MyTbl as ADOX.Table

set MyDB = CreateJetCatalog("C:\MyData.mdb)
set MyTbl = CreateYourTable
MyDB.Tables.Append MyTbl
End Sub

Function CreateJetCatalog(ByVal strFIlename as String) _
as ADOX.Catalog

Dim cat As New ADOX.Catalog

cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilename

Set CreateJetCatalog = cat
End Sub

Sub CreateYourTable() as ADOX.Table
Dim tbl as ADOX.Table

Set tbl = New ADOX.Table
tbl.Columns.Append "Service Date", adDate
tbl.Columns.Append "Cost", adCurrency
tbl.Columns.Append, "Odometer", adBoolean
tbl.Columns.Append, "Fuel Qty", adBoolean
tbl.Columns.Append, "Service Type", adVarChar, 96

set CreateYourTable = tbl
End Sub

(thanks to Scarhead for this snippet)


Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top