I have a access table which exports a PDF report using 'DoCmd.output' for each record in the recordset using a loop.
The query the report is based on takes around 10-15 seconds to run due to some complex calculations in the query. I think this delay is effecting the loop command as it moves on to the next record while the 'DoCmd.output' is still processing.
The below code will correctly export one report in PDF format to the specified folder but it will not continue the loop and stops executing any more code below the loop. (It does not freeze, you can continue working with the Form but the hourglass is showing as it did not run the line 'DoCmd.hourglass False'
When I remove the code to create the pdf report the loop runs perfectly.
Anyone got any ideas, basically I want the loop to wait until the report is exported fully before moving to the next record.
The query the report is based on takes around 10-15 seconds to run due to some complex calculations in the query. I think this delay is effecting the loop command as it moves on to the next record while the 'DoCmd.output' is still processing.
The below code will correctly export one report in PDF format to the specified folder but it will not continue the loop and stops executing any more code below the loop. (It does not freeze, you can continue working with the Form but the hourglass is showing as it did not run the line 'DoCmd.hourglass False'
When I remove the code to create the pdf report the loop runs perfectly.
Anyone got any ideas, basically I want the loop to wait until the report is exported fully before moving to the next record.
Code:
Public Strexclusions As String
Public StrExclusionsDetail As String
Public StrExclCount As Integer
Public Strwhere As String
Public DataLock As Boolean
Public RecordSetLoaded As String
Private Sub txtStatementInc_AfterUpdate()
If Me.txtStatementInc = True Then
If MsgBox(" Press OK to prepair statements for export" & vbNewLine & " This will take a significant time for large mailers", vbOKCancel + vbDefaultButton2, " CONFIRM ACTION ") = vbOK Then
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@...........Set Recordset........@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Dim MyDB As Database
Dim MyRS As Recordset
Dim MyRSfilter As String
DoCmd.Hourglass True
Set MyDB = CurrentDb
RecordSetLoaded = "CreditControlSummary"
MyRSfilter = "SELECT * FROM " & RecordSetLoaded & " WHERE " & Strexclusions & " And " & Strwhere
Set MyRS = MyDB.OpenRecordset(MyRSfilter)
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@...........Start Loop...........@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
MyRS.MoveFirst
Do Until MyRS.EOF
Dim strstatementname As String
Dim FSO As Object, TmpFolder As Object
Set FSO = CreateObject("scripting.filesystemobject")
Set TmpFolder = FSO.GetSpecialFolder(2)
strstatementname = "Communal_Account_Statement" & MyRS![Account Number]
DoCmd.OutputTo acOutputReport, "ccStatement", acFormatPDF, TmpFolder & _
"\" & strstatementname & ".pdf", False
'............................................................
'............................................................
MyRS.MoveNext
Loop
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@.............End Loop...........@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
MsgBox ("Export Complete")
DoCmd.Hourglass False
Else
Me.txtStatementInc = False
If Me.txtAccBalanceInc = False Then
RecordSetLoaded = "CreditControlSummaryQuick"
Else
'Do Nothing
End If
End If
Else
End If
End Sub