Hide Command Button (1 Viewer)

CanWest

Registered User.
Local time
Yesterday, 19:22
Joined
Sep 15, 2006
Messages
272
I have a form with three text boxes and one command button

I want to hide the command button from view until at least one of the boxes has data in it. I also want the command button to return to hidden if the data is removed

So far I have tried this on the after update event on one zof the text boxeswith absolutely no success.

Code:
    If Me.txtFirstName = "" And Me.txtLastName = "" And Me.txtSocialInsuranceNumber = "" Then
        Me.cmdAddNewClient.Visible = False
    Else
        Me.cmdAddNewClient.Visible = True
    End If

Any assistance, guidance or insight would be greatly appreciated.
 

CanWest

Registered User.
Local time
Yesterday, 19:22
Joined
Sep 15, 2006
Messages
272
I used a variation of your code on this page but still got the same results. It does make the control hidden but if you remove the data it comes back with no criteria error.

Here is the code

Code:
    If Len(Me.txtFirstName & vbNullString) = 0 Then
        Me.cmdAddNewClient.Visible = False
    Else
        Me.cmdAddNewClient.Visible = True
    End If

and this only this only does one of the three text boxes
 

nanscombe

Registered User.
Local time
Today, 02:22
Joined
Nov 12, 2011
Messages
1,082
I would check to see whether the three fields, you could add more by concatenating them, had any characters in them.

You would have to check in the Current() event of the Form and also the AfterUpdate() event of each of the controls.

Code:
Private Sub isNewClientVisible()
Dim strTemp as String
  strTemp = nz(Me.txtFirstName) & nz(Me.txtLastName) & nz(Me.txtSocialInsuranceNumber)
  Me.cmdAddNewClient.Visible = (Len(strTemp) > 0)
End Sub

Private Sub Form_Current()
  isNewClientVisible
End Sub

Private Sub txtFirstName_AfterUpdate()
  isNewClientVisible
End Sub

Private Sub txtLastName_AfterUpdate()
  isNewClientVisible
End Sub

Private Sub txtSocialInsuranceNumber_AfterUpdate()
  isNewClientVisible
End Sub
 

CanWest

Registered User.
Local time
Yesterday, 19:22
Joined
Sep 15, 2006
Messages
272
This too works great until you delete data in one of the text boxes. Then you get a pop up that says No criteria and the title bar reads nothing to do
 

nanscombe

Registered User.
Local time
Today, 02:22
Joined
Nov 12, 2011
Messages
1,082
There are no criteria involved in the code above nor does it change the title bar, so I suspect there is something being affected elsewhere.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:22
Joined
Aug 30, 2003
Messages
36,128
I don't see how any of this code would throw that kind of error either. What happens if you take all this code out and follow the same process?
 

CanWest

Registered User.
Local time
Yesterday, 19:22
Joined
Sep 15, 2006
Messages
272
I am with both of you but it does. I will investigate further
 

nanscombe

Registered User.
Local time
Today, 02:22
Joined
Nov 12, 2011
Messages
1,082
Can you get a screenshot, that might help.

Does the phrase "no criteria" appear somewhere in your code if you do a search.
 

CanWest

Registered User.
Local time
Yesterday, 19:22
Joined
Sep 15, 2006
Messages
272
Can you get a screenshot, that might help.

Does the phrase "no criteria" appear somewhere in your code if you do a search.

Here is a screen shot of the small dialogue box that appears
 

Attachments

  • NoCriteria.JPG
    NoCriteria.JPG
    13.4 KB · Views: 47

CanWest

Registered User.
Local time
Yesterday, 19:22
Joined
Sep 15, 2006
Messages
272
Ahha, I got it. Thanks for the trigger nanscombe. There is other code on the after update of these three fields. This form is a filter form to determine if a client exists. As soon as all three text boxes were blank and Information msgbox was triggered to let the user know there was nothing to filter. As it should be. So all I did was change the msgbox text to be more informative and all is good. Thanks everyone.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:22
Joined
Aug 30, 2003
Messages
36,128
Happy to help!
 

Users who are viewing this thread

Top Bottom