Not a Member Yet,
Click here to Register
How do you like the new design?






ID: 279
Viewed: 2396
Added: Jul 26, 2002
Version:
Snippet uploaded by: snippet
Written By: unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

A few times I've had a Form with a lot of TextBoxes on it, and all of them had to be filled by the user.
If even one TextBox was left empty, the program could not proceed. Rather than looping manually through every TextBox on the Form, I came up with the following: A function with the Form as a single argument. Loop through each control on the Form, (using "For Each Control etc") and if it's a TextBox which is empty, it returns Err.Number = 0.
If this is true, I change the BackColor of the offending TextBox to light pink, and the function returns True. (If the TextBox is not empty, and it's BackColor is light pink, I return the BackColor to white. One can store the original color and restore it.) Then call Err. Clear, and continue in the loop. All TextBoxes which are empty will show up as light pink.

To test, create a Form with several TextBoxes on it; their names are immaterial, and they can even be in some container, like a Frame. Create a Command Button, named TestEmpty. Following is the code:

Run the program. Fill in some of the TextBoxes, and click on the Command Button, You will see the empty TextBoxes BackColor change to light pink. If you fill these in and click again, their BackColor will change to white. Note: If the procedure is in a Module, then the argument is the Form name.

Highlight all by clicking in box
<!---Declaration--->
none

Highlight All
<!---Code--->
Private Sub TestEmpty_Click() 
If IsEmpty(Me) Then
MsgBox "Some textboxes are still empty"
End If
End Sub


Function IsEmpty(Frm As Form) As Boolean
Dim tmpControl As Control
On Error Resume Next
IsEmpty = False
For Each tmpControl In Frm.Controls
If Trim(tmpControl.Text) = "" Then
If Err.Number = 0 Then
IsEmpty = True
tmpControl.BackColor = &HFFC0FF 'light pink
End If
Err.Clear Else
If tmpControl.BackColor = &HFFC0FF Then tmpControl.BackColor = QBColor(15) 'White
End If
End If
Next tmpControl
End Function
;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions