LeiDBug007
Technical User
Greetings Experts,
We’ve got a form that has 7 fields, and a close command button at the bottom.
We want to ensure that the user cannot leave the form when there are null values in any of the fields.
We currently have a code that works perfectly and prevents the user from creating a new record when there are null values.
Here is the code:
*******************************************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Integer
For i = 0 To Controls.Count - 1
If TypeOf Controls(i) Is TextBox Or _
TypeOf Controls(i) Is ComboBox Then
If IsNull(Controls(i)) Then
MsgBox "You must enter data in each field!"
Controls(i).SetFocus
End
End If
End If
Next i
End Sub
*******************************************************
HOWEVER……. It still allows the user to click on the close button and close the form – even with null values!?
HELP!!!!! Thanx!
We’ve got a form that has 7 fields, and a close command button at the bottom.
We want to ensure that the user cannot leave the form when there are null values in any of the fields.
We currently have a code that works perfectly and prevents the user from creating a new record when there are null values.
Here is the code:
*******************************************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Integer
For i = 0 To Controls.Count - 1
If TypeOf Controls(i) Is TextBox Or _
TypeOf Controls(i) Is ComboBox Then
If IsNull(Controls(i)) Then
MsgBox "You must enter data in each field!"
Controls(i).SetFocus
End
End If
End If
Next i
End Sub
*******************************************************
HOWEVER……. It still allows the user to click on the close button and close the form – even with null values!?
HELP!!!!! Thanx!