Before_Update Event (1 Viewer)

Oludare

New member
Local time
Today, 16:49
Joined
Jan 28, 2021
Messages
24
Hello All,

My validation code in the before_update event is not activated on click of the save button on my form.
Please help. My code is below.

Private Sub Form_BeforeUpdate(Cancel As Integer)


If Me.cboReissueReason.Value = "" Then
MsgBox "This is mandatory. Please Select a Reissue Reason", vbOKOnly
Cancel = True
Me.cboReissueReason.SetFocus
Exit Sub
End If

If Me.cboEstatepfx = "" Or IsNumeric(Me.cboEstatepfx) Then
MsgBox "Please correct Invalid Data at EstateNamePrefix field.", vbOKOnly
Cancel = True
Me.cboEstatepfx.SetFocus
Exit Sub
End If



If Me.txtEstateBordereauNo = "" Or Not IsNumeric(Me.txtEstateBordereauNo) Then
MsgBox "Please correct Invalid Data at EstateBordereauNo field.", vbOKOnly
Cancel = True
Me.txtEstateBordereauNo.SetFocus
Exit Sub
End If

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:49
Joined
May 7, 2009
Messages
19,169
if textbox has no value, you must use IsNull([textbox])
or
Me.textbox & "" = "" (to test for blank)

for combo, use it's ListIndex property:

If Me!combo.ListIndex = -1 then '(no selection or invalid selection has been made)
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:49
Joined
Jan 23, 2006
Messages
15,364
You could insert a line in your code to see if this routine is being executed.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Debug.print "Testing to ensure Form_BeforeUpdate is being executed"
---your other code here
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:49
Joined
May 21, 2018
Messages
8,463
Also possibly, the docmd.save does not do what most people think. It is about saving objects not records.
The Save method works on all database objects that the user can explicitly open and save. The specified object must be open for the Save method to have any effect on the object.

If you leave the ObjectType and ObjectName arguments blank (the default constant, acDefault, is assumed for the ObjectType argument), Microsoft Access saves the active object.

If you leave the ObjectType argument blank, but enter a name in the ObjectName argument, Access saves the active object with the specified name.

If you enter an object type in the ObjectType argument, you must enter an existing object's name in the ObjectName argument.
Notice the word record is not discussed.

How about me.dirty = false, instead in the button?
 

isladogs

MVP / VIP
Local time
Today, 16:49
Joined
Jan 14, 2017
Messages
18,186
Or use the Nz function Nz(Me.textbox,"")="". Note that .Value isn't required your code as its the default
 

Oludare

New member
Local time
Today, 16:49
Joined
Jan 28, 2021
Messages
24
Thanks all for the suggestions. It now works ok.
IsNull(Textbox) and Me.Combo.ListIndex = -1 applied.

Many thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:49
Joined
May 7, 2009
Messages
19,169

Oludare

New member
Local time
Today, 16:49
Joined
Jan 28, 2021
Messages
24
Hello All.

I get Access validation error message when validation rule is invalid. How do i suppress this message please?

Regards
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:49
Joined
May 21, 2018
Messages
8,463
If you are coding your own validation then you do not need a validation rule. So remove it.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:49
Joined
Oct 29, 2018
Messages
21,358
Hello All.

I get Access validation error message when validation rule is invalid. How do i suppress this message please?

Regards
Hi. Do you still get the message if you Cancel the BeforeUpdate event? Just curious...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:49
Joined
Feb 19, 2002
Messages
42,971
Put a stop on the first line of code in the BeforeUpdate event. This event cannot be bypassed. If the record is dirty, this is the last event that will be executed before the record is saved. On a bound form, you can't get around it.

Is your form not bound?
 

Users who are viewing this thread

Top Bottom