Checking for missing data

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

Guest

Hello,

I have a form where all the variables should be filled in. The problem is
that sometimes some of the data are missing. My supervisor wants to have
prompt when closing the form, to go back if a question has been left blank .
Is there any easy way to check on all the variables? What would be the most
efficient way to check for missing values?
Thanks,

BK
 
Go to the table design view and change the Required property for the needed
fields from No to Yes. This will require the user to place a value in the
field.
 
But that will force them to enter a data...All I need is a prompt to let them
know they should check for missing as it is possible that the respondent did
not answer a question.
Thanks,

BK
 
Heh. Well you did say easy.

But aside from my comment from what I am aware of it would require some VB
code or tricky use of conditional statments. Both of which are beyond me to
be able to explain and/or do.

Sorry i couldn't help more.
 
I did some research and I recommend you do a search for the topic "Check for
null" there is a discussion started by the user Newbie that may answer your
question.
 
Marshall Barton, MVP suggested the following code for a similar problem. I
think the same code would work for you too.

Set the Tag property of each bound control that you want to check to
something like CHECK. Then you could use a loop like this air code:

Dim ctl As Control
Dim strEmpty As String
Dim strMsg As String
For Each ctl In Me.Controls
If ctl.Tag = "CHECK" Then
If IsNull(ctl) Then
strEmpty = strEmpty & vbCrLf & Ctl.Name
End If
End If
Next ctl
If strEmpty <> "" Then
strMsg = "These fields are missing a value" _
& Mid(strEmpty, 3) & vbCrLf & vbCrLf _
& "are you sure you want to save?"
If MsgBox(strMsg, . . . ) = vbYes Then
Me.Dirty = False
End If
End If

Hope this helps.

PS
 
Hello,

I have a form where all the variables should be filled in. The problem is
that sometimes some of the data are missing. My supervisor wants to have
prompt when closing the form, to go back if a question has been left blank .
Is there any easy way to check on all the variables? What would be the most
efficient way to check for missing values?

Put VBA code in the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If IsNull(Me!txtThisRequiredField) Then
MsgBox "You must fill in This Required Field", vbOKOnly
Cancel = True
Me!txtThisRequiredField.SetFocus
End If
<etc for other fields>
End Sub

John W. Vinson[MVP]
 
Back
Top