Originally Posted by
vvwstcat
Thanks. I have done a bit of readings. It seems that Access modules have to be associated with forms or reports before they can be referenced. Mine one is a general module, not assoicated with any object. it could be the reason Access cannot find it. Anyway, it is very disappointed to see such limitation. I meant to do automation. if theere is no alternative, I then continue to handle it mannually.
A function or sub within a code module cannot have the same name as the code module.
The above macro Runcode argument must be Function Name =GenStockReports()
The = is required
Then make sure the code procedure in that renamed module actually is a Function:
Code:
Public Function GenStockReports()
Dim Outfile As String
On Error GoTo GenStockReports_Err
Outfile = Application.CurrentProject.Path & "" & "DailyStockReport US.xls"
DoCmd.OutputTo acOutputQuery, "QryStockReport", "Excel97-Excel2003Workbook(*.xls)", Outfile, False, "", , acExportQualityPrint
Outfile = Application.CurrentProject.Path & "" & "DailyOptionReport US.xls"
DoCmd.OutputTo acOutputQuery, "QryOptionReport", "Excel97-Excel2003Workbook(*.xls)", Outfile, False, "", , acExportQualityPrint
GenStockReports_Exit:
Exit Function
GenStockReports_Err:
MsgBox Error$
Resume GenStockReports_Exit
End Function