Run-Time error 2108

  • Thread starter Thread starter Hungry
  • Start date Start date
H

Hungry

Hi.
I am receiving the error in the Subject box. Below is my code:

Private Sub Salary_BeforeUpdate(Cancel As Integer)
'Verify the Bonus Quota field value is 40 and if so Salary must be less
than or equal to 30,000
If BonusQuota = 40 Then
If Salary > 30000 Then
DoCmd.CancelEvent
MsgBox "If Bonus Quota is 40, Salary must be LE 30,000"
Me.Undo
Salary.SetFocus
End If
End If

End Sub
The error message reads: You must save the field B4 you execute the
GoToControl action, the GoToControl method, or the SetFocus method.

What is wrong?
Thank You
 
You can't change the focus from within the beforeupdate event. And you
are also assuming that the /other/ field is the one that is wrong.
Perhaps it isn't - perhaps /this/ field is the one that is wrong! If
you got your current scheme to work, it would move the cursor to the
wrong field, 50% of the time.

Here's what I'd do. Make the message /nonfatal/. (That is, make the
message a warning only. Remove the cancelevent, undo & setfocus.) Then
the user can navigate freely back & forth between the fields, to get
the values corresponding.

Then, do the check again, in the BeforeUpdate event of the /form/. If
the two values do not correspond, display a message and then just say:
Cancel=True That will stop the form from continuing. The user
will have to move the cursor back to whatever field that /he/ decides
is wrong, & fix the value.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Back
Top