'Before Update' Code Not Working (1 Viewer)

lhooker

Registered User.
Local time
Today, 04:37
Joined
Dec 30, 2005
Messages
399
Can anyone tell me why the below code works in my 'Event Procedure' code behind a 'Button' and not when I move the code to 'Event Procedure' for 'Before Update' ? When I tab pass an empty (blank) text boxes, it does not produce the pop-up error message. The code works with the 'Button' 'Event Procedure'.

If IsNull([First_Name]) Then
MsgBox "Please enter your first name.", , " Missing First Name"
SurveyError = "On"
[First_Name].SetFocus
GoTo Bottom
End If
 

moke123

AWF VIP
Local time
Today, 04:37
Joined
Jan 11, 2013
Messages
3,912
Form before update or control before update? I'm assuming control before update and if you are just tabbing past the control it is not updating and the event is not firing. you should do your validation in the forms before update.
 

lhooker

Registered User.
Local time
Today, 04:37
Joined
Dec 30, 2005
Messages
399
Moke123,

Are you saying I should continue my validation process in the 'Button' 'Event Procedure' ?
 

missinglinq

AWF VIP
Local time
Today, 04:37
Joined
Jun 20, 2003
Messages
6,423
Are you saying I should continue my validation process in the 'Button' 'Event Procedure' ?

No...

...you should do your validation in the forms before update.

If the Control is Null (empty) you'll need to cancel the Record's being saved, and Canceling the event isn't available in the OnClick event of a Command Button, but it is in the Form_BeforeUpdate event.

Also, when validating for Null (empty) Controls, you never use Events connected to the Control in question (i.e TextboxName_BeforeUpdate, TextboxName_AfterUpdate, etc) because all the OP has to do to beat the validation is to simply not enter the Control!

Linq ;0)>
 
Last edited:

Solo712

Registered User.
Local time
Today, 04:37
Joined
Oct 19, 2012
Messages
828
Can anyone tell me why the below code works in my 'Event Procedure' code behind a 'Button' and not when I move the code to 'Event Procedure' for 'Before Update' ? When I tab pass an empty (blank) text boxes, it does not produce the pop-up error message. The code works with the 'Button' 'Event Procedure'.

If IsNull([First_Name]) Then
MsgBox "Please enter your first name.", , "Missing First Name"
SurveyError = "On"
[First_Name].SetFocus
GoTo Bottom
End If

I am with missinglinq on this. Use the form's BeforeUpdate event and cancel if the text is not entered in the individual controls. Change the code to the following:
Code:
If Nz([First_Name])= "" Then   ' catches Null and zero length string
       MsgBox "Please enter your first name.", , "        Missing First Name"
        Cancel = True
       [First_Name].SetFocus
       Exit Sub
    End If

This should work with no issues.

Best,
Jiri
 

Users who are viewing this thread

Top Bottom