Field check before update

wdenboer

Registered User.
Local time
Today, 11:21
Joined
Feb 4, 2009
Messages
14
Hi all,

I am rather new in the world of access and a search though this website did not give any results. The problem is as follows.

background:
I have a drop-down box with user names in it coming from a table. In time more user will be working with the database and therefore I added an 'add' button. Clicking the button will result is a new form called 'frm_add_user'.

On the 'frm_add_user' the are two fields; Username and abbreviation. and a 'ok' button.

Problem:
when the OK button is clicked, the entered data should be added to a table called 'tbl_user'. But if one of the fields is left empty it should give a error message and not enter the date to the table.

I have tried many things like a before update event and many more. Whatever I do the result is the same and the table is updated with blank fields.

I hope somebody can help me with this.

Kind regards
Wouter

Code:
'Private Sub frm_newuser_beforeUpdate(Cancel As Integer)

'check whether all field are filled
If IsNull(Me.Username) Then
MsgBox "user name is required"
If IsNull(Me.abbreviation) Then
MsgBox "abbreviation is required. Maximum is 4 Characters"
cancel = True
End If

DoCmd.SetWarnings True
GoTo ExitUpdate:
End If

End Sub
 
This is a stab in the dark - If the test(s) fail you should do:

DoCmd.CancelEvent
 
When properly indented, can you see the problem?
Code:
Sub frm_newuser_beforeUpdate(Cancel As Integer)

'check whether all field are filled
   If IsNull(Me.UserName) Then
      MsgBox "user name is required"
      If IsNull(Me.abbreviation) Then
         MsgBox "abbreviation is required. Maximum is 4 Characters"
         Cancel = True
      End If

      DoCmd.SetWarnings True
      GoTo ExitUpdate:
   End If

End Sub
BTW, where is ExitUpdate? You're not leaping out of this sub routine are you?
 

Users who are viewing this thread

Back
Top Bottom