form validation

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

Guest

I am sure this one has been asked before, but I couldn't find an example in the search.

How can I check all of text boxes in my form to ensure that the user has filled them all in?
 
I am sure this one has been asked before, but I couldn't find an example in the search.

How can I check all of text boxes in my form to ensure that the user has filled them all in?

Without knowing more, here is one possible answer.

In the Form's BeforeUpdate event:

Dim c As Control
For Each c In Controls
If TypeOf c Is TextBox Then
If IsNull(c) Then
MsgBox c.Name & " is not filled in."
End If
End If
Next

If the form includes combo boxes, check boxes, etc., that must also
be filled in, add them to the above code:
If Type of c is TextBox or TypeOf c is CheckBox or .... Then
 
Try the following code:
=== Code Starts ===
Private Function fTxtBoxFilled () as Boolean
Dim ctlTMP as Control
'Dim strControlTypes as String

fTxtBoxFilled = True

'strControlTypes = "acTextBox;acComboBox;acListBox"
''You have to provide all kind of control types you want to check
separated with ';'

For each ctlTMP in Me.Controls
If ctlTMP.ControlType = acTextBox Then
'If InStr(1, strControlTypes, ctlTMP.ControlType)<>0 Then
If Nz(ctlTMP.Value, "") = "" Then
fTxtBoxFilled = fTxtBoxFilled And False
Else
fTxtBoxFilled = fTxtBoxFilled
End If
End If
Next

End Function
=== Code Ends ===

With this function you can check if all text boxes are filled.
Alternativilly you can un-remark the lines in the code and check for any
type of control.
(You will have to delete thaw one of the two If statements).
Margaritis Paktitis
Ï "tom said:
I am sure this one has been asked before, but I couldn't find an example in the search.

How can I check all of text boxes in my form to ensure that the user has
filled them all in?
 
Back
Top