Before Update

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a drop down (lookup field) and when the user selects a record that is
currently locked, on the Before Update property I am displaying an error
message and then I set cancel = false and exit sub. How do I set the drop
down field to empty again? When the user tries to go to another drop down
(lookup field) they get the same error message - can't get out of the drop
down.
Here is my code:

Private Sub cboFileNumberLookup_BeforeUpdate(Cancel As Integer)
sLookupType = "File"
CheckIfLocked
If bLockedRecord = True Then 'Record is locked, get out and reset field to
empty
Cancel = True
'Set the drop down field to "" or Null
'cboFileNumberLookup = "" ' Access doesn't allow this statement
Exit Sub
End If
 
If the combo box is bound to a field in its Control Source try

Me.cboFileNumberLookup.Undo

If it's not bound, try

Me.cboFileNumberLookup = Null
 
Yes I did try setting the unbound field to NULL as well as setting it to "".
I get an error still. The error is "The macro or function set to
BeforeUpdate property for this field is preventing new importing programs
from saving the data in the field.

Unsure how to proceed. I need the user to beable to go to another lookup
field (this BeforeUpdate code prevents them from going anywhere else, even on
close of the form).

Thank you VERY much for helping!!!!!!

- Janis in Minnesota :)
 
Sorry, you can't change the value of the control whose BeforeUpdate event
you're running it the BeforeUpdate event. You have to do it in the
AfterUpdate event. If this is an unbound control, skip the Cancel of the
update in the BeforeUpdate event, just set the value to Null in the
AfterUpdate event. If it is a bound control, you would Cancel and Undo in
the BeforeUpdate event.
 
Back
Top