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

Hiding controls (i.e. Command Buttons) on a form 1

Status
Not open for further replies.

supportguy21

Technical User
Dec 15, 2002
13
CA
Hello again,

Background
I have created a data entry form that contains several Command Buttons - one is called "Search"; another is called "Add record". I have also created a switchboard (that appears on start-up) that has two options: 1. Search/Edit and 2. Add a new record. Both selections point to the same form in question.

Question
Is it possible to "hide" Command Buttons on the form depending on which Switchboard option is selected. Specifically, when the user selects the "Search/edit" option from the switchboard, the "Add record" command button on the form is hidden (and vice-versa).

Thanks
 
If ytou have a global variable like HideWhichButton

And set it to something when you click a button on the switch board.

Global HideWhichButton < this needs to be in a module

sub AddRec_click
HideWhichButton = &quot;add&quot;
docmd.OpenForm ......
end sub

in the form in question
have this in the On_load procedure

If HideWhichButton =&quot;add&quot; then
Add_Command_Button.visible = True
Search_Command_Button.visible = False
else
Add_Command_Button.visible = False
Search_Command_Button.visible = True
end if DougP, MCP
 
Rather than use a global variable (they should get used as little as possible, in general), I would just pass the name of the button clicked in the OpenArgs of the form and then run a test in the Open event.

Private Sub Command1_Click()
call docmd.OpenForm(&quot;frmYadda&quot;,,,,,,&quot;Command1&quot;)
end sub

Private Sub Command2_Click()
call docmd.OpenForm(&quot;frmYadda&quot;,,,,,,&quot;Command2&quot;)
end sub

Private Sub Form_Open(Cancel As Integer)
Dim strButton As String

strButton = Me.OpenArgs
Select Case strButton
Case &quot;Command1&quot;
Me!someButton.Visible = False
Me!someOtherButton.Visible = True
Case &quot;Command2&quot;
Me!someButton.Visible = True
Me!someOtherButton.Visible = False
Case &quot;Command3&quot;
'This is just here to show that you can handle several different cases here
Me!someButton.Visible = False
Me!someOtherButton.Visible = False
Case Else
Call MsgBox(&quot;You opened this form illegally. It will be shut down.&quot;, vbExclamation)
Call DoCmd.Close(acForm, Me.Name)
End Sub

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Just one more FYI....I would not recommend hiding the buttons.....just disable them. Users sometimes get a little wierd when they notice buttons disappearing and reappearing.....just set the enabled property to no....The user still sees the button, but can't use it. Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
That is of course, unless you want to put the two buttons on top of each other and display on or the other...then the button doesn't disappear to the user...just changes functions.... Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Heh. And again I'll agree with Robert's refinement of my approach!

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
And BTW Jeremy.....I AM NOT following you around and agreeing with you....we jsut seem to be hitting the same threads lately..... :) Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Thanks for the useful feedback - hiding the button is a much better option.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top