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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running Access from Excel and Closing Connection

Status
Not open for further replies.

NYFashionToGo

Technical User
Jan 16, 2007
76
US
I am running some code from excel to print sales receipts out.... In sequence with some shipping labels... After this routine runs.. If I need to open up access ( for whatever reason) it is giving me a message saying I do not have exclusive access to the database at this time....

Is there anything I am doing wrong here in this code below that will get rid of that message and close the connection. So I can open it up and work inside...

Thanks



Sub Step7PrintSalesReceipt()




Dim appAcc As Object
Set appAcc = CreateObject("Access.Application")
appAcc.Visible = False

appAcc.OpenCurrentDatabase ("C:\Documents and Settings\Chris\My Documents\NYFashionToGo\NYFOrderProcessingNewEdition.mdb")



On Error GoTo ErrorHandler

appAcc.DoCmd.OpenReport "Sales Receipt", acPrint, , "[ShippingLabel]='PRIORITY'"
appAcc.DoCmd.OpenReport "Sales Receipt", acPrint, , "[ShippingLabel]='FIRST'"
appAcc.DoCmd.OpenReport "Sales Receipt", acPrint, , "[ShippingLabel]='EXPRESS'"
appAcc.DoCmd.OpenReport "Sales Receipt", acPrint, , "[ShippingLabel]='INTLAIRLETTER'"
appAcc.DoCmd.OpenReport "Sales Receipt", acPrint, , "[ShippingLabel]='INTLGPM'"
appAcc.DoCmd.OpenReport "Sales Receipt", acPrint, , "[ShippingLabel]='INTLGEM'"
appAcc.DoCmd.OpenReport "Sales Receipt", acPrint, , "[ShippingLabel]='INTLAIRPARCEL'"

ExitHandler:
Exit Sub

ErrorHandler:

' This traps the Output to Error message
If Err = 2501 Then
Resume ExitHandler

Else
MsgBox Err.Description
Resume ExitHandler

End If


appAcc.Quit
End Sub
 
It looks like you don't close the Access application after you use it. That is, the subroutine never gets to appAcc.Quit.

_________________
Bob Rashkin
 
appAcc.DoCmd.OpenReport "Sales Receipt", [!]2[/!], , "[ShippingLabel]='PRIORITY'" ' 2=acViewPreview

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top