On Error Problem

G

Guest

I have a form with a control that contains the following code:

========================================
Private Sub Invoice_AfterUpdate()
On Error GoTo InvoiceDone
V_Looper = True
DoCmd.GoToRecord , , acFirst
Me.IndividualRecordInvoice = Me.Invoice
Do While V_Looper = True
Me.IndividualRecordInvoice = Me.Invoice
DoCmd.GoToRecord , , acNext
Loop
InvoiceDone:
On Error GoTo ReceiptDateDone
V_Looper = True
DoCmd.GoToRecord , , acFirst
Me.IndividualRecordInvoiceReceiptDate = Me.ReceiptDate
Do While V_Looper = True
Me.IndividualRecordInvoiceReceiptDate = Me.ReceiptDate
DoCmd.GoToRecord , , acNext
Loop
ReceiptDateDone:
Me.InvoiceDate.SetFocus
End Sub
=================================================

The first do loop does what I wanted it to do, which is change all the
records on the form. [Invoice]

The second do loop errors on the "DoCmd.GoToRecord , , acNext" statement.
Run Time error 2105, " You cannot go to the specified record".

I would have thought that the " On Error GoTo ReceiptDateDone" line would
have taken care of it.

Does anyone have any idea why this would occur?
 
G

Guest

Maurice,

Thanks for your quick response. I am not aware that "on error exit do" is a
valid on error parameter. Am I missing something?

Maurice said:
I think you should catch the error by exiting the loop. So catch the error
before the DoCmd.GoToRecord , , acNext in the second loop with something
like on error exit do.

hth
--
Maurice Ausum


tkosel said:
I have a form with a control that contains the following code:

========================================
Private Sub Invoice_AfterUpdate()
On Error GoTo InvoiceDone
V_Looper = True
DoCmd.GoToRecord , , acFirst
Me.IndividualRecordInvoice = Me.Invoice
Do While V_Looper = True
Me.IndividualRecordInvoice = Me.Invoice
DoCmd.GoToRecord , , acNext
Loop
InvoiceDone:
On Error GoTo ReceiptDateDone
V_Looper = True
DoCmd.GoToRecord , , acFirst
Me.IndividualRecordInvoiceReceiptDate = Me.ReceiptDate
Do While V_Looper = True
Me.IndividualRecordInvoiceReceiptDate = Me.ReceiptDate
DoCmd.GoToRecord , , acNext
Loop
ReceiptDateDone:
Me.InvoiceDate.SetFocus
End Sub
=================================================

The first do loop does what I wanted it to do, which is change all the
records on the form. [Invoice]

The second do loop errors on the "DoCmd.GoToRecord , , acNext" statement.
Run Time error 2105, " You cannot go to the specified record".

I would have thought that the " On Error GoTo ReceiptDateDone" line would
have taken care of it.

Does anyone have any idea why this would occur?
 
G

Guest

I think you should catch the error by exiting the loop. So catch the error
before the DoCmd.GoToRecord , , acNext in the second loop with something
like on error exit do.

hth
 
G

Guest

Maurice,

I must be stupid!! I am still wondering why it doesn't work, but I really
have no need for the second do loop. I can do all the changes in one loop!
ARRGH! Sometimes it is so obvious you can't see it! Anyhow, thanks, I am
still wondering why it doesn't work.

Maurice said:
I think you should catch the error by exiting the loop. So catch the error
before the DoCmd.GoToRecord , , acNext in the second loop with something
like on error exit do.

hth
--
Maurice Ausum


tkosel said:
I have a form with a control that contains the following code:

========================================
Private Sub Invoice_AfterUpdate()
On Error GoTo InvoiceDone
V_Looper = True
DoCmd.GoToRecord , , acFirst
Me.IndividualRecordInvoice = Me.Invoice
Do While V_Looper = True
Me.IndividualRecordInvoice = Me.Invoice
DoCmd.GoToRecord , , acNext
Loop
InvoiceDone:
On Error GoTo ReceiptDateDone
V_Looper = True
DoCmd.GoToRecord , , acFirst
Me.IndividualRecordInvoiceReceiptDate = Me.ReceiptDate
Do While V_Looper = True
Me.IndividualRecordInvoiceReceiptDate = Me.ReceiptDate
DoCmd.GoToRecord , , acNext
Loop
ReceiptDateDone:
Me.InvoiceDate.SetFocus
End Sub
=================================================

The first do loop does what I wanted it to do, which is change all the
records on the form. [Invoice]

The second do loop errors on the "DoCmd.GoToRecord , , acNext" statement.
Run Time error 2105, " You cannot go to the specified record".

I would have thought that the " On Error GoTo ReceiptDateDone" line would
have taken care of it.

Does anyone have any idea why this would occur?
 

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