I have inherited someone else's database and process. There is a report that would not work. The problem lies in the code but I do not know enough to fix it.
I turned on all Warnings to help me determine where the problem is. The queries loop continuously as expected but when 0 rows are returned the loop needs to stop.
I have determined this because if I hit No when it asks to return 0 records the report appears in perfect condition. Can someone help me with the EscapeEndlessLo op that they appear to be using but is not working.
I turned on all Warnings to help me determine where the problem is. The queries loop continuously as expected but when 0 rows are returned the loop needs to stop.
I have determined this because if I hit No when it asks to return 0 records the report appears in perfect condition. Can someone help me with the EscapeEndlessLo op that they appear to be using but is not working.
Code:
Private Sub cmdPrintLabels_Click()
DoCmd.SetWarnings True
DoCmd.OpenQuery "qdClearLabelQuantities"
DoCmd.OpenQuery "qdClearLabels"
DoCmd.OpenQuery "qaLabelQuantity"
DoCmd.SetWarnings True
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim prm As ADODB.Parameter
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "qsLabelQuantityNotZeroNew"
cmd.CommandType = adCmdTable
cmd.Parameters.Refresh
For Each prm In cmd.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = cmd.Execute
DoCmd.SetWarnings True
Do
DoCmd.OpenQuery "qaPartNumberLabels"
DoCmd.OpenQuery "quQuantityMinusOneNew"
On Error GoTo EscapeEndlessLoop
rst.MoveFirst
Loop
EscapeEndlessLoop:
rst.Close
Set rst = Nothing
Set cmd = Nothing
DoCmd.SetWarnings True
DoCmd.OpenReport "rlPartNumbers", acViewPreview
End Sub
Comment