validation rule giving me "run time error 2115" grief

simeon_rose

Registered User.
Local time
Today, 10:14
Joined
Nov 4, 2000
Messages
34
hi i've got a form with a textbox on it showing Dmax result from an unrelated table. i've also got another textbox on the same form into which i want the user to enter the output given in the Dmax textbox. when the user doesn't do this, i've set up an error message in the before update event but this is then immediately followed by run time error 2115 rather than just resetting the focus to the ID textbox. this is the code that i've used:

Private Sub ID_BeforeUpdate(Cancel As Integer)

If Me.ID <> Forms!frmtblcar!Text17 Then
MsgBox "Incorrect Entry, You should enter " & Forms!frmtblcar!Text17, 0, "Error"
Me.ID = ""
Me.ID.SetFocus

End If
End Sub

could somebody please point me in the right direction?

p.s: i've tried putting the code in other events, but invariably there are other problems with this.
 
Why not just put Me![ID] = Forms!frmtblcar!Text17 in the On Enter event of the field and as the user tabs into the field the correct data will be entered for them?

If you need to do it the other way then modify your code like this:

If Me.ID <> Forms!frmtblcar!Text17 Then
MsgBox "Incorrect Entry, You should enter " & Forms!frmtblcar!Text17, 0, "Error"
Me.ID = ""
Me![AnotherField].SetFocus
Me![ID].SetFocus
End if

[This message has been edited by Jack Cowley (edited 12-10-2000).]
 
i've tried both your suggestions, unfortunately, neither of them work. when i try to enter the line of code suggested in the 'on enter' event, i get an error message telling me that the 'macro' isn't recognised (even though i didn't enter it as a macro) and when i try adjusting the actual code i had anyway, i get exactly the same problem. it displays the error message i want it to, and then on clicking on OK i get the runtime error message again.
please help!
 
Try moving it to the before update of the form
If IsNull(Me.ID)Or Me.ID <> = Me.Text17 Then
Cancel = True
your msg.
Text17.SetFocus
 
thanks for the above suggestion...i no longer get that other run time error, however, i do now get run time error 2108 saying that i must save the field before executing the setfocus function. i don't kniw how to get around this, do any of you?
 
Are you sure you have the code on the Form Before update and not the control?
 

Users who are viewing this thread

Back
Top Bottom