I inherited a previous employees project in Access 2010 and need to fix a loop that locks the database. I set Warnings to True in the code to see where the problem is so that I could escape out and avoid the lockup. After pressing Yes to append rows from about 30 tables the query eventually returns 0 records. Choosing NO pulls up the report perfectly. However, it isn't very effective to sit and press the ENTER key 20 times every time I need the report. I can't seem to find the right combination of code to make this work and there is no documentation on the project. Any help would be appreciated. The code is below. I've tried a variety of rst.Move commands and MoveFirst is the only thing that seems to call these queries correctly.
Code:
Private Sub cmdPrintLabels_Click() DoCmd.SetWarnings False 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 While Not rst.EOF DoCmd.OpenQuery "qaPartNumberLabels" DoCmd.OpenQuery "quQuantityMinusOneNew" On Error GoTo EscapeEndlessLoop rst.MoveFirst Loop EscapeEndlessLoop: rst.Close Set rs = Nothing Set cmd = Nothing DoCmd.SetWarnings True DoCmd.OpenReport "rlPartNumbers", acViewPreview End Sub
Comment