Error Trapping VBA

W

Wayne-I-M

Hi All

I have an unbound (continous) subform that users can select a record and
then go to the corresponding record on the main form (with recordset clone).
I set the focus to a text box on the main form - which is the problem as this
has a "OnGotFocus" event. = Basically users select a subform record go to the
main form and other "stuff" runs.

"It all works fine" other than erorr message 2110 telling me You Can Go To
The Text Box. (which of course you can)

I have tried getting rid of the message with docmd.warnings false then true

and also trapping the error with

Private Sub Form_Click()
On Error GoTo Form_Click_Err
'......
RecordsetClone "stuff" goes here
'......
Err_Form_Click:

Select Case Err.Number
Case 2110
Resume Exit_Form_Click
MsgBox Err.Description
Resume Exit_Form_Click
End Select
End Sub

This line is highlighted
Resume Exit_Form_Click

Any help would be good as I have spent hours on this and obviously doing
"som-it" wrong.

As I said it all works fine other than the iritating message

Many thanks for any tips.
 
D

Douglas J. Steele

Have you got a line label Exit_Form_Click in the procedure? (You haven't
shown it...)

However, even if you do, that's not going to do what you want. You're
missing the Case Else statement, so that an error message will be produced
if the error isn't 2110:

Select Case Err.Number
Case 2110
Resume Exit_Form_Click
Case Else
MsgBox Err.Description
Resume Exit_Form_Click
End Select
 
W

Wayne-I-M

Hi Douglas

Thanks for your time

I am getting Compile error - lable not defined
with
Resume Exit_Form_Click
highlighted


--
Wayne
Manchester, England.



Douglas J. Steele said:
Have you got a line label Exit_Form_Click in the procedure? (You haven't
shown it...)

However, even if you do, that's not going to do what you want. You're
missing the Case Else statement, so that an error message will be produced
if the error isn't 2110:

Select Case Err.Number
Case 2110
Resume Exit_Form_Click
Case Else
MsgBox Err.Description
Resume Exit_Form_Click
End Select
 
W

Wayne-I-M

The full code is


Private Sub Form_Click()
On Error GoTo Form_Click_Err

Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetID =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!PayMainID
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetST =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!Statement

Forms!frmPaymentMain!hiddentxt =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetID
Forms!frmPaymentMain.SetFocus
Forms!frmPaymentMain!hiddentxt.SetFocus

Set rst = Me("frmPaymentItems_datasheet").Form.RecordsetClone
rst.FindFirst "PayMainID = " &
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!PayMainID
Me("frmPaymentItems_datasheet").Form.Bookmark = rst.Bookmark

Err_Form_Click:

Select Case Err.Number
Case 2110
Resume Exit_Form_Click
Case Else
MsgBox Err.Description
Resume Exit_Form_Click
End Select
--
Wayne
Manchester, England.



Douglas J. Steele said:
Have you got a line label Exit_Form_Click in the procedure? (You haven't
shown it...)

However, even if you do, that's not going to do what you want. You're
missing the Case Else statement, so that an error message will be produced
if the error isn't 2110:

Select Case Err.Number
Case 2110
Resume Exit_Form_Click
Case Else
MsgBox Err.Description
Resume Exit_Form_Click
End Select
 
D

Douglas J. Steele

The Resume statement says "GoTo Exit_Form_Click", but you don't have a label
Exit_Form_Click anywhere for it to go to!

Private Sub Form_Click()
On Error GoTo Form_Click_Err

Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetID =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!PayMainID
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetST =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!Statement

Forms!frmPaymentMain!hiddentxt =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetID
Forms!frmPaymentMain.SetFocus
Forms!frmPaymentMain!hiddentxt.SetFocus

Set rst = Me("frmPaymentItems_datasheet").Form.RecordsetClone
rst.FindFirst "PayMainID = " &
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!PayMainID
Me("frmPaymentItems_datasheet").Form.Bookmark = rst.Bookmark

Exit_Form_Click:
Exit Sub

Err_Form_Click:

Select Case Err.Number
Case 2110
Resume Exit_Form_Click
Case Else
MsgBox Err.Description
Resume Exit_Form_Click
End Select


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Wayne-I-M said:
The full code is


Private Sub Form_Click()
On Error GoTo Form_Click_Err

Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetID =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!PayMainID
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetST =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!Statement

Forms!frmPaymentMain!hiddentxt =
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!txtsetID
Forms!frmPaymentMain.SetFocus
Forms!frmPaymentMain!hiddentxt.SetFocus

Set rst = Me("frmPaymentItems_datasheet").Form.RecordsetClone
rst.FindFirst "PayMainID = " &
Forms!frmPaymentMain!frmPaymentItems_datasheet.Form!PayMainID
Me("frmPaymentItems_datasheet").Form.Bookmark = rst.Bookmark

Err_Form_Click:

Select Case Err.Number
Case 2110
Resume Exit_Form_Click
Case Else
MsgBox Err.Description
Resume Exit_Form_Click
End Select
 
W

Wayne-I-M

Thank you Douglas

This was the problem Err_Form_Click:
Should have been Form_Click_Err:

Thanks for spotting it.

Oh well - off to the pub now to watch England win the rugby world cup now ???
 
D

Douglas J. Steele

You're right: I missed that. However, you were missing Exit_Form_Err, and
your Select Case statement was wrong too.
 

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

Top