I have made a macro in Access that import the data from a CSV into a table that is connected to a report. It then deletes the records in the table (to clear it out), then it brings up the print dialog screen so the user can select a printer to print the report onto. After the user selects the printer and the report prints, I want to close out of MS Access. I have tried sending the keystrokes %{F4} (Alt + F4) but this does not work as it closes the print dialog screen. :banghead: How would I go about closing/exiting MS Access after the previous macros have run? Would this be a sub macro? Sleep method? Any tips would be greatly appreciated!
Below is the macro vba code...
Function AutoExec()
On Error GoTo AutoExec_Err
DoCmd.TransferText acImportDelim, "DynamicsPartsLabels Import Specification1", "DynamicsPartsLabels", "\\~\DynamicsPartsLabels.csv", True, "" //Imports data from csv into table
DoCmd.OpenReport "Labels LabelTemplate", acViewReport, "", "", acNormal //opens the report that I want to print
DoCmd.RunSQL "DELETE FROM DynamicsPartsLabels", -1 //deletes records from table
SendKeys "~", True //enter key that exits warning message
SendKeys "^p", True //opens print dialog screen
DoCmd.Quit acExit //Quit MS Access
AutoExec_Exit:
Exit Function
AutoExec_Err:
MsgBox Error$
Resume AutoExec_Exit
End Function
Below is the macro vba code...
Function AutoExec()
On Error GoTo AutoExec_Err
DoCmd.TransferText acImportDelim, "DynamicsPartsLabels Import Specification1", "DynamicsPartsLabels", "\\~\DynamicsPartsLabels.csv", True, "" //Imports data from csv into table
DoCmd.OpenReport "Labels LabelTemplate", acViewReport, "", "", acNormal //opens the report that I want to print
DoCmd.RunSQL "DELETE FROM DynamicsPartsLabels", -1 //deletes records from table
SendKeys "~", True //enter key that exits warning message
SendKeys "^p", True //opens print dialog screen
DoCmd.Quit acExit //Quit MS Access
AutoExec_Exit:
Exit Function
AutoExec_Err:
MsgBox Error$
Resume AutoExec_Exit
End Function
Last edited: