Can't re-open Access database from Excel VBA
I have an Excel application that through VBA opens an Access database, works
on it, and then closes it. This functions well.
But when I re-open it, I do not get a correct connection to the database.
I have extracted a small portion of my VBA and included it below. What is
wrong ?
I use CurrentDB to check whether all is OK.
I get the following error message :
Run-tiome error '-2147417848 (80010108)':
Automation Error
The object invoked has disconnected from its clients.
In my application from which the VBA below is extracted (and simplified) I
get the following error message :
Run-time error '462':
The remote server machine does not exist or is unavailable
'========================== VBA start ==========================
Option Explicit
Const wInDB As String = "C:\WILMAR\Wilmar database.mdb"
Public InAccess As Object
Sub HVL_Write_Queries()
' You need a reference to Microsoft Access 9.0 Object Library
' Use menu "Tools / References".
Dim OK As Boolean
Dim X As Object
OK = Open_Access_InDB
Set X = CurrentDB ' This is OK.
OK = Close_Access_InDB
OK = Open_Access_InDB
Set X = CurrentDB ' ERROR !
OK = Close_Access_InDB
End Sub
Function Open_Access_InDB() As Boolean
Dim Exclusive_Mode As Boolean, OK As Boolean
Exclusive_Mode = False
OK = True
If InAccess Is Nothing Then
Set InAccess = New Access.Application
InAccess.OpenCurrentDatabase wInDB, Exclusive_Mode
End If
InAccess.Visible = False
Open_Access_InDB = OK
End Function
Function Close_Access_InDB() As Boolean
Close_Access_InDB = True
InAccess.Quit acQuitPrompt ' This makes the Access window visible. No
database open.
Set InAccess = Nothing
End Function
'========================== VBA end ==========================
|