Check to see if database object is open
Posted on 2004-10-11
With the following how do I check and see if the database object has opened? I can check to be if it is set to something, but how do I check to see if it has been opened or not?
Global dbsNew As Database
Set dbsNew = wrkDefault.CreateDatabase(DBFilename, _
Set dbsNew = wrkDefault.OpenDatabase(DBFilename)
I tried the following, but this only shows if the database has been set. If the code fails between the first statement
above and the next statement, how do I know the correct way to clean up my connections? If the database is open, I want to run the SQL statement below, otherwise nothing really happened, so I don't.
If the first statement runs, and the second does not, the following code executes the else, but dbsNew is not open and the execute does not work.
If Not dbsNew Is Nothing Then
strSQL = "INSERT INTO RunInfo (Program_Started, SQL_Finished, DB_Created, Register_Loaded_Count, Values_Updated_Count) "
strSQL = strSQL & "VALUES (#" & Format(dtStarted, "YYYY-MM-DD HH:MM:SS") & "#, #"
strSQL = strSQL & Format(dtSQLProcessed, "YYYY-MM-DD HH:MM:SS") & "#, #"
strSQL = strSQL & Format(dtDBCreated, "YYYY-MM-DD HH:MM:SS") & "#,"
strSQL = strSQL & intRecordCounter1 & ", " & intRecordCounter2 & ");"
Set dbsNew = Nothing