Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(txtLastName) Then
MsgBox "Please enter a last name!"
DoCmd.GoToRecord , , acLast
Me.ctlLastName.SetFocus
End If
End Sub
Name: ctlLastName
Control Source: txtLastName
This is a simple routine that works in "the CornerBookstore" but for
some reason I can't get the message box to appear in one of my
applications. Code is as shown.
Any suggestions appreciated.
It appears the name of the control on the form is ctlLastName, not
txtLastName.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([ctlLastName]) Then
MsgBox "Please enter a last name!"
Cancel = True
Me.ctlLastName.SetFocus
End If
End Sub
Cancel = True cancels the save.
Focus is then returned to the ctlLastName control on the current
record.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail- Hide quoted text -
- Show quoted text -
Thanks for your resonses.
The following two versions seem to give me what I would expect.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([txtLastName]) = True Then
MsgBox "Please enter a last name!"
DoCmd.GoToRecord , , acLast
Me.ctlLastName.SetFocus
End If
End sub
AND #2 is
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(ctlLastName) = True Then
MsgBox "Please enter a last name!"
DoCmd.GoToRecord , , acLast
Me.ctlLastName.SetFocus
End If
End Sub
Notice ctlLastName in one and [TxtLastName] in the other.
So now my question is this...... What exactly am I testing for???
a) Am I testing that the control ctlLastName is empty OR
b) Am I testing that the value in the underlying table is empty OR
c) none of the above.
Next question .... If we assume that either one of the above is
correct and the user gets returned to the ctlLastNAme to correct the
fact they didn't fill it and the AGAIN leave it blank ..... the above
code allows the entry. How would you repeat the message box until they
got it right without getting into a continuous LOOP as I did.
Seems everything I do gets more complicated as I go. Thanks for any
enlightenment.