Validating that data was entered into a text Box
I have a Signin form (frmSignIn) with two Text Boxes asking for a UserName (txtName) and Password (txtPassword). The form also has two command buttons Enter (cmdEnter) and Add User (cmdAddUser).
I would like to validate that data has been entered into the text boxes before processing the form.
I have tried the following VBA Code in the BeforeUpdate event for the text Box.
Option Compare Database
Option Explicit
Private Sub txtName_BeforeUpdate(Cancel As Integer)
If txtName = “” Or IsNull(txtValue) Then
MsgBox “You are a Dummy”
Cancel = True
End If
End Sub
This only works if I enter a value in the txtName Box and then backspace to erase the value.
What am I doing wrong?
I have a Signin form (frmSignIn) with two Text Boxes asking for a UserName (txtName) and Password (txtPassword). The form also has two command buttons Enter (cmdEnter) and Add User (cmdAddUser). I would like to validate that data has been entered into the text boxes before processing the form. I have tried the following VBA Code in the BeforeUpdate event for the text Box. Option Compare DatabaseOption ExplicitPrivate Sub txtName_BeforeUpdate(Cancel As Integer) If txtName = “” Or IsNull(txtValue) Then MsgBox “You are a Dummy” Cancel = True End IfEnd Sub This only works if I enter a value in the txtName Box and then backspace to erase the value. What am I doing wrong? Read More