Require user to fill in 4 fields....if null then a message box

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...
Example that I found...


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


HOW CAN I MAKE THIS WORK FOR ALL FIELDS....

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

Vince
 
R

Ron Weiner

How about Something like

if len(nz(field1.value,"")) = 0 then
strmsg = strmsg & "Field1 must not be empty" & vbcrlf
end if
if len(nz(field2.value,"")) = 0 then
strmsg = strmsg & "Field2 must not be empty" & vbcrlf
end if
if len(nz(field3.value,"")) = 0 then
strmsg = strmsg & "Field3 must not be empty" & vbcrlf
end if
if len(nz(field4.value,"")) = 0 then
strmsg = strmsg & "Field4 must not be empty" & vbcrlf
end if
if len(strmsg > 0 then
msgbox "Invalid entry(ies) in:" & vbcrlf & vbcrlf & strmsg
cancel = true
end if
 
M

Michel Walsh

Hi,


If possible, do it at the design table level. Specify the field is
required and do not allow zero length string. Alternatively, in the Before
Update event of the FORM, you can test:

If IsNull(Me.field1) Then
Cancel=True
MsgBox " Record is to be saved, but Field1 requires a value,
please supply a value and try again. ", "Error", vbOkOnly
Exit Sub
End If

If IsNull(Me.Field2) Then
...





Hoping it may help,
Vanderghast, Access MVP
 
V

Vince

Thanks!!

No worries, it's been set at the table level, this way is
to dummy proof the data entry....never take them for
granted, they are the best DEBUGGERS in the world.
-----Original Message-----
Hi,


If possible, do it at the design table level. Specify the field is
required and do not allow zero length string. Alternatively, in the Before
Update event of the FORM, you can test:

If IsNull(Me.field1) Then
Cancel=True
MsgBox " Record is to be saved, but Field1 requires a value,
please supply a value and try again. ", "Error", vbOkOnly
Exit Sub
End If

If IsNull(Me.Field2) Then
...





Hoping it may help,
Vanderghast, Access MVP



Vince said:
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...
Example that I found...


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


HOW CAN I MAKE THIS WORK FOR ALL FIELDS....

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

Vince


.
 

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