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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable command button if any textboxes are not null

Status
Not open for further replies.

fishtek

Technical User
Aug 21, 2002
56
0
0
US
I have a search form that i want to disable a command button on if any unbound text boxes contain text. I've tried various code with various events but none work. Thanks for any help.
 
Have you tried:

If Len(Nz(TextBox, "")) = 0 Then
Me.CommandButton.Enable = True
Else
Me.CommandButtonEnable = False
End If


Place this in your Form.Current and Form.Load section.

:)WB
 
How are ya fishtek . . .
[ol][li]In the [blue]Tag[/blue] property of the [blue]Unbound Texboxes[/blue] of interest, enter a question mark [purple]?[/purple] (no quotations please).[/li]
[li]In the code module of the form, copy/paste the following routine:
Code:
[blue]Public Sub ButCtl()
   Dim ctl As Control
   
   For Each ctl In Me.Controls
      If ctl.Tag = "?" Then
         If Trim(ctl & "") <> "" Then
            Me![purple][B][I]ButtonName[/I][/B][/purple].Enabled = False
            Exit For
         End If
      End If
   Next

End Sub[/blue]
[/li]
[li]In design view of the form, the [blue]Enable[/blue] property of the button should be set to [blue]Yes[/blue].[/li]
[li]Finally, in the [blue]AfterUpdate[/blue] event of the same unbound textboxes with the question mark, copy/paste the following:
Code:
[blue]   Call ButCtl[/blue]
[/li][/ol]
[blue]Your Thoughts? . . .[/blue]


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
fishtek . . .

A second look reveals my code is not quite right. To correct, replace the routine [blue]ButCtl[/blue] with the following:
Code:
[blue]Public Sub ButCtl()
   Dim ctl As Control, Tag As Integer
   
   For Each ctl In Me.Controls
      If ctl.Tag = "?" Then
         If Trim(ctl & "") <> "" Then Tag = Tag + 1
      End If
   Next

   Me![purple][B][I]ButtonName[/I][/B][/purple].Enabled = (Tag = 0)
   
End Sub[/blue]

Cheers! [thumbsup2] . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks Aceman!!!!
I works great. The only thing is I had to place the whole Sub code under the AfterUpdate Event for every textbox. When I just tried to call the Sub as you instructed I got an error message that it was looking for a macro. Thanks again for your help!!
 
fishtek said:
[blue] . . . I had to place the whole Sub code under the AfterUpdate Event for every textbox.[/blue]
I fully tested this and you should only have to make the call from the unBound Textboxes.

By chance did you put the call on the event line instead of within the actual event?

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Ahhhh.... my bad.
Thanks Aceman1.
 
fishtek . . .

Do have a look at one of the links at the bottom of my post. The links will help you [blue]ask better questions[/blue], get [blue]quick responses[/blue], [blue]better answers[/blue], and insite into [blue]etiquette[/blue] here in the forums. [thumbsup2]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top