Forcing a user to complete a field before saving the record

T

Tony Williams

I have a form that I want to ensure that the user completes their name in one
of the controls before the record is saved. I have a message created in the
Before Update of the form but although the message appears I can't get back
into the control to enter the name. I have that control locked and think I
may have the code in the incorrect event. here is my forms VBA code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.txtenteredby) Then
MsgBox "Please enter your name in the Entered By box before saving this
record", vbOKOnly
End If
End Sub

Private Sub Form_Current()
If Me.NewRecord Then
Me.txtActionLog.Locked = False
Me.txtenteredby.Locked = False
Else
Me.txtActionLog.Locked = True
Me.txtenteredby.Locked = True
End If

End Sub

Private Sub txtActionLog_AfterUpdate()
If Me.NewRecord Then
Me.txtTimeDate = Now
End If

End Sub

Could someone point me to where I'm going wrong?
Thanks
Tony
 
D

Douglas J. Steele

You've forgotten to set Cancel in the BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.txtenteredby) Then
MsgBox "Please enter your name in the " & _
"Entered By box before saving this record", _
vbOKOnly
Cancel = True
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top