This is an Excel VBA Issue. I have an excel app that reads data and runs some complex queries in an Access DB and returns the data to Excel. I have a process that opens access. This runs everytime the user initiates a query from Excel.
When the user closes excel, I have another process that closes Access. However, it is possible that the user decides not the close excel when prompted with a Save dialog box. At that point, Access has been closed.
Code:
Set objAccess = GetObject(, "Access.Application")
If (Err.Number <> 0) Then
'Or (objAccess.CurrentDb.Name <> sDBName)
Set objAccess = Nothing
Set objAccess = CreateObject("Access.Application")
objAccess.Visible = False
objAccess.OpenCurrentDatabase (sDB)
Else
End If
When the user closes excel, I have another process that closes Access. However, it is possible that the user decides not the close excel when prompted with a Save dialog box. At that point, Access has been closed.
Code:
Set objAccess = GetObject(, "Access.Application")
'** if err <> 0, then access is not open
If (Err.Number <> 0) Then
Else
objAccess.Quit
Set objAccess = Nothing
End If
[\code]
When this situation occurs, if the user initiates another query, the code:
Set objAccess = GetObject(, "Access.Application")
no longer recognizes that Access is not running. The err.Number returns a zero. So further down the code, the code crashes when the application tries to read from a table in the Access database, because the Access db is not open.
Anyone have any thoughts why the code no longer properly recognizes the status of Access (running or not running) and have a solution or workaround.
Thanks.