Controling 'Visability' of Command Button

  • Thread starter Thread starter Noel
  • Start date Start date
N

Noel

Hi. I am using XP and Access 2002. I have a Form which is
displayed in two ways - one via a Tab Control forms Tab
and the other on the click of a command button
(cmdOpenForm). I have a command button on the Form
(cmdReturn) which I want to be visible only if the form
is opened using the cmdOpenForm button. I do not want the
button visable when the form is viewed by clicking on its
Tab. Is there some code I could put in the Tab Control
Forms 'On Change' Event to make cmdReturn not visable and
some code I could put in the 'On Click' Event of
cmdOpenForm to make cmdReturn Visable? Thanks, Noel
 
Noel said:
Hi. I am using XP and Access 2002. I have a Form which is
displayed in two ways - one via a Tab Control forms Tab
and the other on the click of a command button
(cmdOpenForm). I have a command button on the Form
(cmdReturn) which I want to be visible only if the form
is opened using the cmdOpenForm button. I do not want the
button visable when the form is viewed by clicking on its
Tab. Is there some code I could put in the Tab Control
Forms 'On Change' Event to make cmdReturn not visable and
some code I could put in the 'On Click' Event of
cmdOpenForm to make cmdReturn Visable? Thanks, Noel

So, in other words, the form may be displayed both in a subform control
and as a standalone form, and you want the button to be displayed only
if the form is displayed as a standalone form?

If that's right, you could have code like this in the Open event of the
form itself -- not the tab control or command button on the parent form:

'----- start of code -----
Private Sub Form_Open(Cancel As Integer)

Dim blnImASubform As Boolean

On Error Resume Next
blnImASubform = IsObject(Me.Parent)
Me.YourCommandButtonName.Visible = Not blnImASubform

End Sub

'----- end of code -----

(substituting the name of the command button you want to show or hide
for "YourCommandButtonName").
 
Thanks Dirk - just tried it and it works perfectly. Looks
like Im keeping you busy today - thats two of my posts
youve replied to this afternoon. Thanks again, Noel
 
Noel said:
Thanks Dirk - just tried it and it works perfectly. Looks
like Im keeping you busy today - thats two of my posts
youve replied to this afternoon.

<g> Well, so far I'm only one for two, but I hope to improve my
average.
 
Back
Top