Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable button until text boxes are filled.

Status
Not open for further replies.

SeadnaS

Programmer
May 30, 2011
214
Does anybody have any code I could use? I have a button that runs a macro and i need to have it greyed out until 9 text boxes are filled. Basically i dont want users hitting the button unless they have entered information into these 9 boxes. The text boxes are all bound to fields in my table.

Thanks in advance for any help!
 
I would do this with code. You could set the Tag property of each of the required text boxes to "Required". Then add a function to the form like:
Code:
  Public Function AllDone() as Boolean
    Dim ctl as Control
    AllDone = True
    For Each ctl in Me.Controls
      If ctl.Tag = "Required"
        If IsNull(ctl) then
          AllDone = False
        End If
      End If
    Next
    Me.cmdButtonName.Enabled = AllDone
  End Function
Set the After Update property of each of these text boxes to
Code:
After Update:   =AllDone()
You might want to add this function to the On Current event of the form.


Duane
Hook'D on Access
MS Access MVP
 


Does anybody have any code I could use?
Not right off hand.

What code have you tried so far?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
How are ya SeadnaS . . .

Try this variationof [blue]dhookom's[/blue] code:
Code:
[blue]Public Function AllDone() As Boolean
    Dim ctl As Control
    
    AllDone = True
    
    For Each ctl In Me.Controls
      If ctl.Tag = "Required" Then
         If Trim(ctl & "") = "" Then
           AllDone = False
           Exit For
         End If
      End If
    Next
    
    Me.cmdButtonName.Enabled = AllDone
  
End Function[/blue]
[blue]Your Thoughts? . . .[/blue]

BTW [blue]SkipVought[/blue], looks like your working with [blue]SeadnaS[/blue]!

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
tried this code... followed instructions however button is still available while text boxes remain zero?! just so you know i have an input mask of 00.00 on all 9 text boxes...
Help!
 
Replace this:
If Trim(ctl & "") = "" Then
with this:
If Val(ctl & "") = 0 Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV that grey's out the button but it doesn't change when all text boxes are filled in.. It just stays grey.... any ideas?
 
Ahh, it works but not the way i want. I have to click in a completely different text box (an un tagged one) to enable the button. Does anyone know why this would be?
 
None of us can see how/where you are calling the function. Please confirm that you did everything I suggested in my first reply. Don't just state "yes I did it". Tell us exactly what you did.

Duane
Hook'D on Access
MS Access MVP
 
I used the tags on all boxes, placed =AllDone() in the after update event boxes of each text box i placed the vb code you gave me at the bottom of the module. Replaced the name of the button in the code.

It works but when i fill in all the boxes it doesnt enable unless i click on another textbox.
 
The after update will only fire after a control has been updated. If the cursor is still in the text box, it hasn't been updated yet. Is it imperative that the command button be enabled prior to the last of the required text boxes loses focus?

Duane
Hook'D on Access
MS Access MVP
 
Well, we will probably get complaints from the people who are going to be using this application. But if theres no way around it then i'll just leave the last text box untagged i guess.

Thanks again for your help.
 
You could modify the code to run in the on change or some other event. The On Change would probably need to look at the Text property of the active control since its actual value might not have been updated.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top