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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6: change database in runtime?

Status
Not open for further replies.

acjeff

Programmer
Aug 10, 2004
148
US
In a VB6 program, I put this in a module to open a database on the startup form:

dbname = GetSetting("myCompany", "DataBaseName", "FileName", ".")
Set db = DBEngine.Workspaces(0).OpenDatabase(dbname, , True)

Say, the database named is myDB.mdb. When the program is running, some timer controls are running all the time in the background. Then on an option page, users can change the database file, say, from myDB.mdb to myDB1.mdb. So I use:

newDB = myDB1.mdb
SaveSetting "myCompany", "DataBaseName", "FileName", newDB
Set db = DBEngine.Workspaces(0).OpenDatabase(newDB, , True)

Now the problem is any pages already loaded (including the start up page) are still pointing to the old database. Moreover, both myDB.mdb and myDB1.mdb files are staying open in the hard drive, that is, 2 corresponding ldb files exist.

1. How can I close the old database file and make its ldb file disappear? I tried using db.close before setting db to newDB but came up with errors from some background timers.

2. How can I refresh my whole program so that it points to the new database file?

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top