I have a sales sytem in Access 2010. New customers have to be imported to MYOB daily. I have a query that finds new customers and appends them to a table for importing at a later stage. I export the records in that table if the field "imported" is set to false. The results are exported to Excel so they can be imported into MYOB after some additional data is added. If there are no records to append to the import table I want to stop the export from happening. I am new to VBA and don't know how to express that the select query "000 Append New Customers...." should only run if the append query has records. If there are no records found, I want to put a message saying "no records found". Can someone please help. I am sure this is really simple, but I am learning so much at the moment I think I am confusing myslef and I am unsure of how to do it.
Here is the code I have behind the command button:
Private Sub PrepCustcmd_Click()
'Turn warnings off
DoCmd.SetWarnings False
DoCmd.OpenQuery "000 Append New Customers to MYOB Customers", acViewNormal, acEdit
' This is where I need to have some code that tells VB what to do if no records to append
DoCmd.OpenQuery "200 Select Customers To Import To MYOB", acViewNormal, acEdit
DoCmd.OutputTo acOutputQuery, "200 Select Customers To Import To MYOB", "ExcelWorkbook(*.xlsx)", "R:\Josephine Mellahn\Sales Orders\200 Select Customers To Import To MYOB_" & Format(Date, "yymmdd") & ".xlsx", True, "", , acExportQualityPrint
'Turn warnings on
DoCmd.SetWarnings True
End Sub
Here is the code I have behind the command button:
Private Sub PrepCustcmd_Click()
'Turn warnings off
DoCmd.SetWarnings False
DoCmd.OpenQuery "000 Append New Customers to MYOB Customers", acViewNormal, acEdit
' This is where I need to have some code that tells VB what to do if no records to append
DoCmd.OpenQuery "200 Select Customers To Import To MYOB", acViewNormal, acEdit
DoCmd.OutputTo acOutputQuery, "200 Select Customers To Import To MYOB", "ExcelWorkbook(*.xlsx)", "R:\Josephine Mellahn\Sales Orders\200 Select Customers To Import To MYOB_" & Format(Date, "yymmdd") & ".xlsx", True, "", , acExportQualityPrint
'Turn warnings on
DoCmd.SetWarnings True
End Sub