How to check empty controls on a form?

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

Guest

Hi,

I've a Save Button on a Data Entry form. If controls are empty and the user
tries to press Save button I want to pop up a MsgBox with YES/NO. Is there a
way to check empty controls programatically instead of checking each and
every control (like If control-a.value <> "" and control.b.value <> "" Then
......)

Thanks.
PS
 
PS said:
I've a Save Button on a Data Entry form. If controls are empty and the user
tries to press Save button I want to pop up a MsgBox with YES/NO. Is there a
way to check empty controls programatically instead of checking each and
every control (like If control-a.value <> "" and control.b.value <> "" Then
.....)


Here's an idea. 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
 
Thank you. It works for me.



Marshall Barton said:
Here's an idea. 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
 
Back
Top