Repeat Expression

G

Guest

Sorry, I thought I had this figured out, but I have one more question. I
tried the code and get the message "Compile Error: Next without
For." If I take out the Next, I get a message that there is For without
Next. I must just have something in the wrong spot. Thanks for any help.
This is what I have:

Private Sub CopyInvoiceNumberToAllChecked_Click()

Dim I As Integer
'Move to the first record
DoCmd.GoToRecord , , acFirst
'Create a loop for all the records
For I = 1 To Me.RecordsetClone.RecordCount
With CodeContextObject
DoCmd.SetWarnings False
If (.VendorWasPaid Like "-1") Then
Forms!frmInvoiceReceived!InvoiceNumber =
Forms!frmInvoiceReceived!InvoiceNo
End If
DoCmd.RunCommand acCmdRefresh
DoCmd.GoToRecord , "", acNext

Next I

End With
mcrSetValueInvoiceReceived_Exit:
mcrSetValueInvoiceReceived_Err:
End Sub
 
P

Pat Hartman \(MVP\)

The " End With" is outside the scope of the For. Move it up to just before
the Next or move the With outside the For (probably more efficient)
 
J

John W. Vinson

Sorry, I thought I had this figured out, but I have one more question. I
tried the code and get the message "Compile Error: Next without
For." If I take out the Next, I get a message that there is For without
Next. I must just have something in the wrong spot. Thanks for any help.
This is what I have:

Private Sub CopyInvoiceNumberToAllChecked_Click()

Dim I As Integer
'Move to the first record
DoCmd.GoToRecord , , acFirst
'Create a loop for all the records
For I = 1 To Me.RecordsetClone.RecordCount
With CodeContextObject
DoCmd.SetWarnings False
If (.VendorWasPaid Like "-1") Then
Forms!frmInvoiceReceived!InvoiceNumber =
Forms!frmInvoiceReceived!InvoiceNo
End If
DoCmd.RunCommand acCmdRefresh
DoCmd.GoToRecord , "", acNext

Next I

End With
mcrSetValueInvoiceReceived_Exit:
mcrSetValueInvoiceReceived_Err:
End Sub

Move the End With above the Next I line, or else move the With
CodeContextObject above the For I = line.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top