Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing MS Access 1

Status
Not open for further replies.

B Shirk

Technical User
Jul 18, 2019
9
US
thread181-510401

I have searched high and low for a solution to this.

I have a macro in Access that will open Excel and a specific excel file. Works OK (See code below)
====================================================
Function OpenExcelFromAccess()
Dim MyXL As Object

Set MyXL = CreateObject("Excel.Application")
With MyXL
.Application.Visible = True
.Workbooks.Open "C:\Users\Barry-DTW7\Desktop\Data Collection\Form 1.xls"

End With
End Function
=========================================================

Once the Excel file is open, I want to close the Access database and the Access Application.

I have tried using the "Quit" command in the Macro but the error code says it's not available; even though I choose it from a drop down menu. I have used the "Close database" command and that works, but leaves the Access Application still open.

I am not real familiar with VB. How would I edit the code above to accomplish this.
 
Thanks for the quick input.

As I said before, I'm not real familiar with VB. Where would I add either of these to the code I posted?
 
Assuming you want to open your Excel file and close Access:

Code:
Function OpenExcelFromAccess()
Dim MyXL As Object

Set MyXL = CreateObject("Excel.Application")
With MyXL
    .Application.Visible = True
    .Workbooks.Open "C:\Users\Barry-DTW7\Desktop\Data Collection\Form 1.xls"
End With
[green]
'Close Access
'Do your magic here
[/green]
 End Function


---- Andy

There is a great need for a sarcasm font.
 
Andy,
Thank you. The DoCmd.Quit worked
 
I am glad [thumbsup2]

And welcome to Tek-Tips! :) [pc2]


---- Andy

There is a great need for a sarcasm font.
 
@B Shirk,

To my fellow Keystonestater, albeit in Texas, it is customary, when a member provides an good solution, in addition to a "thank you," to hit the Great post! link to award a little purple star. The stars are not just for the member providing the great post, but also for the benefit of other members browsing for good information.

Hope you'll find much to help you here at Tek-Tips.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top