I need some hand holding on the below syntax. I'd like to change some things, but need to understand a couple lines in the below.
Going line by line...
temp = rs("FileNam") - this is from the recordset - OK
MyFileNam = rs("FileNam") & ".pdf" - this is going to be my filename - OK
I don't understand the below line. It looks like it translates to: rs[FileName]= temp
DoCmd.OpenReport ReportName, acViewPreview, , "[FileNam]='" & temp & "'"
In my mind I think this should work:
DoCmd.OpenReport ReportName, acViewPreview, , MyFileNam ... but it doesn't. Why?
Code:
Public Function BBB_CA()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyFileNam As String
Dim mypath As String
Dim temp As String
Dim PackListQuery As String
Dim ReportName As String
PackListQuery = "qry_PackingList_BBB_CA"
ReportName = "Packing List BBB CA"
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT Distinct [FileNam] FROM " & PackListQuery, dbOpenSnapshot)
Do While Not rs.EOF
temp = rs("FileNam")
MyFileNam = rs("FileNam") & ".pdf"
'acViewPreview = Print Preview, acViewReport = Direct to Printer
DoCmd.OpenReport ReportName, acViewPreview, , "[FileNam]='" & temp & "'"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyFileNam
DoCmd.Close acReport, ReportName
DoEvents
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
thanks!