G
garry.oxnard
I've seen variations of this problem posted on Google Groups when
trying to resolve my own, very similar problem. As far as I can see
no-one has had a eureka moment, but I'm getting desperate and hope
someone can help.
I've designed an Excel template which a lot of users will use to
generate an .xls file.. When the template is run as a document, a macro
button within the worksheet allows them to open up an Access 'Address'
database where they select an address, click a macro button (within
Access) and the address data is pasted into Excel. Access closes.
All works well, apart from the fact that the session between Excel and
Access seems to remain open. I see the previously saved .xls files
listed in the VBA project window (and an equal number of "UNSAVED VBA
Component" references in the VBA References box).
I have tried a variety of ways to end the session between Excel and
Access and explored the various suggestion made by others to a similar
problem, but I'm no further forward. The key parts of my code are as
follows:
1. Opening up the "AddressLookup" Access database from within Excel.
works fine.
Private Sub cmdAddress_Click()
ActiveSheet.Unprotect
Application.DisplayAlerts = False
ThisWorkbook.SaveAs "C:\Decent Homes Data Systems\" & "DHomes1.xls"
Application.DisplayAlerts = True
MsgBox "The Address Lookup database will now open. Please Click OK
and Wait"
Dim ac As Object
On Error Resume Next
Set ac = GetObject(, "Access.Application")
If ac Is Nothing Then
Set ac = GetObject("", "Access.Application")
ac.OpenCurrentDatabase "C:\Decent Homes Data
Systems\AddressLookup.mdb"
ac.UserControl = True
End If
AppActivate "Microsoft Access"
End Sub
2. Access opens and the user selectes an address an clicks the macro
button to send the address back into Excel and close Access. Works
fine.
3. The user clicks the "Save & Close" button in Excel to save the
worksheet and close Excel.
Private Sub cmdClose_Click()
Dim booVar As Boolean
booVar = booValid
strMessage = "Please enter a value in boxes highlighted in green."
Call Validate 'runs a checking procedure to prevent nulls in cells.
booVar = booValid
If Not booVar Then
'strMessage is one line procedure advising user to complete all cells
coloured green.
MsgBox strMessage, 0
Exit Sub
End If
Call CreateValues 'sets values in certain cells prior to delete of
worksheets.
Application.DisplayAlerts = False
ThisWorkbook.SaveAs "C:\Decent Homes Data Systems\" & Range("T2") &
".xls" 'saves workbook in name of unique cell reference
Application.Run "WZTEMPLT.XLA!Commit" 'runs template wizard to fire
record into another Access database. Works fine.
Call ShowToolbars 'turns toolbars on again to minimise file size.
Call DeleteButtons 'deletes macro buttons to minimise file size.
Call DeleteSheets 'deletes unwanted sheets to minimise file size.
Call DeleteForms 'deletes unwanted forms to minimise file size.
Application.DisplayAlerts = False
ActiveWorkbook.Save
Set ac = Nothing
Application.Quit
End Sub
It all works ok (a lot of work) but I just can't crack this final
problem. I would be very grateful if someone could help me out here. I
don't use the Google Desktop bar by the way. I have no COM Add-Ins
operating apart from the Template Wizard.
Thanks all.
trying to resolve my own, very similar problem. As far as I can see
no-one has had a eureka moment, but I'm getting desperate and hope
someone can help.
I've designed an Excel template which a lot of users will use to
generate an .xls file.. When the template is run as a document, a macro
button within the worksheet allows them to open up an Access 'Address'
database where they select an address, click a macro button (within
Access) and the address data is pasted into Excel. Access closes.
All works well, apart from the fact that the session between Excel and
Access seems to remain open. I see the previously saved .xls files
listed in the VBA project window (and an equal number of "UNSAVED VBA
Component" references in the VBA References box).
I have tried a variety of ways to end the session between Excel and
Access and explored the various suggestion made by others to a similar
problem, but I'm no further forward. The key parts of my code are as
follows:
1. Opening up the "AddressLookup" Access database from within Excel.
works fine.
Private Sub cmdAddress_Click()
ActiveSheet.Unprotect
Application.DisplayAlerts = False
ThisWorkbook.SaveAs "C:\Decent Homes Data Systems\" & "DHomes1.xls"
Application.DisplayAlerts = True
MsgBox "The Address Lookup database will now open. Please Click OK
and Wait"
Dim ac As Object
On Error Resume Next
Set ac = GetObject(, "Access.Application")
If ac Is Nothing Then
Set ac = GetObject("", "Access.Application")
ac.OpenCurrentDatabase "C:\Decent Homes Data
Systems\AddressLookup.mdb"
ac.UserControl = True
End If
AppActivate "Microsoft Access"
End Sub
2. Access opens and the user selectes an address an clicks the macro
button to send the address back into Excel and close Access. Works
fine.
3. The user clicks the "Save & Close" button in Excel to save the
worksheet and close Excel.
Private Sub cmdClose_Click()
Dim booVar As Boolean
booVar = booValid
strMessage = "Please enter a value in boxes highlighted in green."
Call Validate 'runs a checking procedure to prevent nulls in cells.
booVar = booValid
If Not booVar Then
'strMessage is one line procedure advising user to complete all cells
coloured green.
MsgBox strMessage, 0
Exit Sub
End If
Call CreateValues 'sets values in certain cells prior to delete of
worksheets.
Application.DisplayAlerts = False
ThisWorkbook.SaveAs "C:\Decent Homes Data Systems\" & Range("T2") &
".xls" 'saves workbook in name of unique cell reference
Application.Run "WZTEMPLT.XLA!Commit" 'runs template wizard to fire
record into another Access database. Works fine.
Call ShowToolbars 'turns toolbars on again to minimise file size.
Call DeleteButtons 'deletes macro buttons to minimise file size.
Call DeleteSheets 'deletes unwanted sheets to minimise file size.
Call DeleteForms 'deletes unwanted forms to minimise file size.
Application.DisplayAlerts = False
ActiveWorkbook.Save
Set ac = Nothing
Application.Quit
End Sub
It all works ok (a lot of work) but I just can't crack this final
problem. I would be very grateful if someone could help me out here. I
don't use the Google Desktop bar by the way. I have no COM Add-Ins
operating apart from the Template Wizard.
Thanks all.