Solved Opening Access then closing Excel, without closing Access (1 Viewer)

Etxezarreta

Member
Local time
Today, 01:44
Joined
Apr 13, 2020
Messages
175
Hello everyone,

I open an Access file from an Excel workbook, then I close the Excel, but the access file closes too: it is maybe more an Excel problem than an Access one, but I am not sure:
here is the code, do you have any recomandation please? Many thanks in advance.
Etxe

Code:
Public Sub FermerFichierExel()

Dim appAccess As Object
Dim strPath As String

strPath = ActiveWorkbook.Path
On Error GoTo errSub

Set appAccess = CreateObject("Access.Application")

Call appAccess.OpenCurrentDatabase(strPath & "\GestionProduction_SupplyChain_LGB.accdb")
appAccess.Visible = True

ActiveWorkbook.Close SaveChanges:=True

Exit Sub
errSub:
    MsgBox Err.Number & " -- " & Err.Description
  
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:44
Joined
Oct 29, 2018
Messages
21,447
Hi. I'm no Excel programmer but maybe use Shell instead of OpenCurrentDatabase. Just a thought...
 

Isaac

Lifelong Learner
Local time
Yesterday, 16:44
Joined
Mar 14, 2017
Messages
8,774
Hello everyone,

I open an Access file from an Excel workbook, then I close the Excel, but the access file closes too: it is maybe more an Excel problem than an Access one, but I am not sure:
here is the code, do you have any recomandation please? Many thanks in advance.
Etxe

Code:
Public Sub FermerFichierExel()

Dim appAccess As Object
Dim strPath As String

strPath = ActiveWorkbook.Path
On Error GoTo errSub

Set appAccess = CreateObject("Access.Application")

Call appAccess.OpenCurrentDatabase(strPath & "\GestionProduction_SupplyChain_LGB.accdb")
appAccess.Visible = True

ActiveWorkbook.Close SaveChanges:=True

Exit Sub
errSub:
    MsgBox Err.Number & " -- " & Err.Description
 
End Sub
After the line appAccess.Visible=True, add this line:

appAccess.usercontrol=true
 

Users who are viewing this thread

Top Bottom