chuckcoleman
Registered User.
- Local time
- Today, 12:42
- Joined
- Aug 20, 2010
- Messages
- 380
Hi, I have a VBA loop that cycles through records, creates a PDF file and outputs the report to a folder. I'm testing on this database and there are only two records in the tables. i have several MsgBox lines in the code below to help me figure out what's going on. Each MsgBox begins with 100, 150, 200 or 300. If I remark-out all of the MsgBoxes, only get ONE PDF's is created. If within the loop MsgBox "100-" is the only one that "runs", two PDF's are created. If within the loop MsgBox "150" is the only one that "runs", two PDF's are created. If within the loop MsgBox "200" is the only one that "runs", ONE PDF is created.
The right behavior is that two PDF's get created. I don't understand why having a MsgBox displayed allows the two PDF's to be created. Why having something like a MsgBox displayed results in any different output is confusing. Any help please.
The right behavior is that two PDF's get created. I don't understand why having a MsgBox displayed allows the two PDF's to be created. Why having something like a MsgBox displayed results in any different output is confusing. Any help please.
Code:
Do Until rs.EOF
MsgBox ("100-Start of Loop and record count is: " & lngCount)
strBind = CStr(rs!BindNbr)
lngCount = lngCount + 1
lblStatus = "Creating invoice " & CStr(lngCount) & " of " & CStr(lngRSCount)
TempVars.Add "strBindCriteria", CStr(strBind)
MsgBox ("150-TempVars is: " & TempVars.Item(StrBindCriteria))
DoCmd.OpenReport strReport, acViewPreview, , "[BindNbr] = " & TempVars.Item(StrBindCriteria)
Reports![Report for emailing dues PDF].Visible = False
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, "C:\HOA\Bulk Invoices\" & strBind & "_Annual Dues.pdf"
rs.MoveNext
DoCmd.Close acReport, strReport
' MsgBox ("200-End of Loop and Record count is: " & lngCount)
Loop
MsgBox ("300-After 'Loop' before 'End if' and Record Count is: " & lngCount)
lblStatus = ""
End If
rs.Close
MyDB.Close
Set rs = Nothing
Set MyDB = Nothing
Close