Form Restriction

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 4 fields in my form - I want to prompt the user with a message if
he/she doesn't fill out every field in the form. "You cannot continue without
completing every field." Forcing the user to not be able to continue. How
can this be accomplished?

Thank you
 
You should put some code in the BeforeUpdate event of the form. For example:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([field1]) Or IsNull([field2]) Or IsNull([field3]) Or
IsNull([field4]) Then
MsgBox "Please complete all the boxes on the form.", vbExclamation,
"Information Missing"
Cancel = True
End If

End Sub

Hope this helps.
Lee
 
Thank you for yout help - Although when I paste the code into my before
update event, the code starting from If IsNull to "Information Missing" is
highlighted in red. I replaced the ([field1]) with my field titles. Do you
know what is happening?

Baby Face Lee said:
You should put some code in the BeforeUpdate event of the form. For example:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([field1]) Or IsNull([field2]) Or IsNull([field3]) Or
IsNull([field4]) Then
MsgBox "Please complete all the boxes on the form.", vbExclamation,
"Information Missing"
Cancel = True
End If

End Sub

Hope this helps.
Lee



Karen said:
I have 4 fields in my form - I want to prompt the user with a message if
he/she doesn't fill out every field in the form. "You cannot continue without
completing every field." Forcing the user to not be able to continue. How
can this be accomplished?

Thank you
 
Sorry for the delay in replying although I expect you've worked out any
problems by now.
The code appears in red if you have any line breaks in it. So the first part
of the If statement (up to 'Then') should be on one line. The message box
statement should all be on the next line.
You can break the code up so that you don't end up with great long lines
that require you to use the horizontal scroll bar (which is a pain) by adding
a space and then and underscore at the end of the line. For example:

If IsNull([Field1]) Or IsNull([Field2]) _


Karen said:
Thank you for yout help - Although when I paste the code into my before
update event, the code starting from If IsNull to "Information Missing" is
highlighted in red. I replaced the ([field1]) with my field titles. Do you
know what is happening?

Baby Face Lee said:
You should put some code in the BeforeUpdate event of the form. For example:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull([field1]) Or IsNull([field2]) Or IsNull([field3]) Or
IsNull([field4]) Then
MsgBox "Please complete all the boxes on the form.", vbExclamation,
"Information Missing"
Cancel = True
End If

End Sub

Hope this helps.
Lee



Karen said:
I have 4 fields in my form - I want to prompt the user with a message if
he/she doesn't fill out every field in the form. "You cannot continue without
completing every field." Forcing the user to not be able to continue. How
can this be accomplished?

Thank you
 

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

Back
Top