Validation Check

Ripley

Registered User.
Local time
Today, 23:04
Joined
Aug 4, 2006
Messages
148
I have some code to check if an unbound text box contains a value or not.
I am checking if it does by using a numeric expression: If all the text boxes contain text, then i can run my code (as the message box "runcode").

To me this seems logical, but it wont work!

Code:
Private Sub Command28_Click()
Dim test1 As Integer
Dim test2 As Integer
Dim test3 As Integer
Dim total As Integer

If Me.Form.box1 = "" Then
test1 = 0
Else
test1 = 1
End If

If Me.Form.box2 = "" Then
test2 = 0
Else
test2 = 1

If Me.Form.box3 = "" Then
test3 = 0
Else
test3 = 1

total = test1 + test2 + test3
If total = 3 Then
MsgBox "Runcode"
Else
MsgBox "A box contains no value!"
End Sub
 
that code is too much just to check if 3 boxes are filled. try this.

Code:
For Each ctl In Me.Controls
        Select Case ctl.ControlType
           Case acTextBox
                    If ctl.Text & "" = "" Then
                        MsgBox "You must fill in all data fields."
                        Exit Sub
                    End If
        End Select
    Next
 

Users who are viewing this thread

Back
Top Bottom