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!
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!