One way to do this is using the BeforeUpdate event of the form. You can loop
through all of your form controls to make sure they aren't null. Once you
find one, you can display a message, cancel the record Add, and place the
focus back on the control. You can either use the ControlSource property of
each control to display the name of the underlying field in your message, or
the Tag property to hold more custom text.
Note that the check for Null will not catch a check box type of control for
a Yes/No field that has not been checked, because it has a value of False.
Dim ctl As Control
For Each ctl In Me.Controls
' See VBA Help for the VB Constants for other data entry controls you
' might be using on your form
If (ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or _
ctl.ControlType = acListBox) Then
If IsNull(ctl) Then
Cancel = True
MsgBox "Please enter a value for " & ctl.ControlSource
' Or, alternatively:
' MsgBox "Please enter a value for " & ctl.Tag
ctl.SetFocus
Exit Sub
End If
End If
Next ctl
Hope that helps.
Sprinks
> i am designing my form for my survey and i want to be able to let people know
> when they missed a question to go back and fill it out. how would i go about
> that?
BruceM - 18 Apr 2005 20:32 GMT
Exactly the sort of thing I was going to be asking soon. Thanks, even though
I'm not the one who asked the initial question.
> One way to do this is using the BeforeUpdate event of the form. You can loop
> through all of your form controls to make sure they aren't null. Once you
[quoted text clipped - 31 lines]
> > when they missed a question to go back and fill it out. how would i go about
> > that?
i am lost in the sauce - 19 Apr 2005 17:17 GMT
what if i dont know any vb or vba. in other words where would i look on my
form for the stuff you told me to do and when i find it how do i put in my vb
code for each one. it looks fairly easy so that must mean its not. if you
could help i would greatly appriciate it. thanks
> One way to do this is using the BeforeUpdate event of the form. You can loop
> through all of your form controls to make sure they aren't null. Once you
[quoted text clipped - 31 lines]
> > when they missed a question to go back and fill it out. how would i go about
> > that?