After Update Event

halem2

Registered User.
Local time
Today, 13:22
Joined
Nov 8, 2006
Messages
180
Good morning you all Access Elders:

running Access 2000.

I have a form with the following code (I found somewhere in the forum and modified it to fit my needs) in the BeforeUpdate event of a form


On Error GoTo Err

If Me.VeroDivisions_ID = "" Or IsNull(Me.VeroDivisions_ID) = True Then
MsgBox "Division can't be left blank"
DoCmd.SetWarnings False
Cancel = True
DoCmd.SetWarnings True
End If

Exit Sub

Err:

but it is not working. I'm trying to force the user to populate the field before moving to the next record.

Can anyone tell me what I'm doing wrong?

thanks.
 
Code:
If (Me.VeroDivisions_ID & ""="") Then
MsgBox "Division can't be left blank"
DoCmd.SetWarnings False
Cancel = True
DoCmd.SetWarnings True
End If
Better way to do this
 
thanks for the help rainman89 but it still doesn't work. Am I using the correct Event? I have it on the BeforeUpdate event of the form.
 
Is this the only field required that u need to have required?
also u should probably put it in the afterupdate of the form. not before

Im sure one of the "Wiser" members here will correct me.
 
yeap, that's the only field. I also tried the AfterUpdate but got nothing either.
 
is the default of the divisionID set to 0 or null?
 
set to null. that's whay I included the evaluation for Null in my original ?

" If Me.VeroDivisions_ID = "" Or IsNull(Me.VeroDivisions_ID) = True Then "
 
If you set default to Null in the table design and then place what i gave u in the after update of the form it will work!
edit: it will throw the error but allow the change
 
Last edited:
Do you have a button that moves to the next record?
if so put this in the buttons on click
Code:
If (Me.VeroDivisions_ID & "" = "") Then
MsgBox "Division can't be left blank"
Cancel = True
Else
DoCmd.GoToRecord , , acNewRec
End If
 
let me try setting it ot null...
and no, I don't have a button. I'm using the form's controls
 
ok then in the table design set it to required. that should fix the problem
 

Attachments

  • required.jpg
    required.jpg
    52.4 KB · Views: 240
your code works just fine when setting the table's default value to Null.

I can KICK myself in the rear for not remembering about the "Required" on the table.

thanks Rainman89...:D
 
Any validation code belongs in the BeforeUpdate event of the form, not the AfterUpdate
 

Users who are viewing this thread

Back
Top Bottom