Loop through all text boxes on a form

armesca

Registered User.
Local time
Yesterday, 21:10
Joined
Apr 1, 2011
Messages
45
I have about 25 text boxes that get populated based on a financial transaction; quite often about half of them are empty. i wanted to gray them out if they are emtpy (.enabled = false). I could put a series of IF statements in the vba for each one, but its bulky and time-consuming. I've done for each record in tables and recordsets. Is there a way to do a for each textbox on a form? Or is there a simpler way to accomplish this? Any thoughts are appreciated.

-Chirs
 
I think you could do it with Conditional Formatting
 
You could also do this in vba:

Code:
dim ctl as control
 
for each ctl in me
    if typeof ctl is textbox or typeof ctl is combobox then
        if nz(ctl, "") = "" then
            ctl.enabled = false
        end if
    end if
next
 
The looping through textboxes is great; conditional formatting is slow
 

Users who are viewing this thread

Back
Top Bottom