Fill in field reminders.....

V

Vince

Hello,

I would like to know if anyone can help a VB super
newbie...

I would like some code to ensure that 4 fields (field1,
field2, field3, field4)are filled out before the 'next'
button is activated. For each field that is missing I
would like a message to popup e.g. Please fill in field
1, etc.....

I found some code but when ever I click ok to the message
it gives me an error code I think 2405 or something...

MANY THANKS TO all you experts in advance I couldn't have
gotten this far...ps THANKS Fredg.

Vince
 
V

Vince

Sure...


Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[Cert Number]) Then
MsgBox "Enter Cert Number First"
Me.[Cert Number].SetFocus
Cancel = True
End If
End Sub
 
J

John Vinson

I would like some code to ensure that 4 fields (field1,
field2, field3, field4)are filled out before the 'next'
button is activated. For each field that is missing I
would like a message to popup e.g. Please fill in field
1, etc.....

Hrm. I'd suggest putting the code in the Form's BeforeUpdate event
(which will fire no matter how the user tries to enter a record,
whether by clicking your Next button, or the builtin nav button, or
closing the form. You have

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[Cert Number]) Then
MsgBox "Enter Cert Number First"
Me.[Cert Number].SetFocus
Cancel = True
End If
End Sub

which should work if you have a textbox on the form named [Cert
Number]).

For what it's worth, I suggest avoiding blanks in fieldnames, and
overriding Access' default of naming a Control identically to the
fieldname; and just to avoid problems if the user enters data in a
field and then backspaces it out, check for both a NULL and a
zero-length string value. I.e.:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.txtCertNumber] & "" = "" Then
MsgBox "Enter Cert Number First", vbOKOnly
Me!txtCertNumber.SetFocus
Cancel = True
End If
<similarly for the other controls>
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