Hiding a button on a subform (1 Viewer)

Robert C

Registered User.
Local time
Today, 13:41
Joined
Mar 27, 2000
Messages
88
I have a form, frmContacts, which sometimes is opened in its own right and sometimes as a subform. I have a button on this form which I would like to make visible only when the form is open on its own. When it is open as a subform I would like the button to be hidden.

Any help would be gratefully received
 

AlaskanDad

Registered User.
Local time
Today, 13:41
Joined
Jun 20, 2000
Messages
39
Something opens the form as either a form or a subform. Your best bet is to set the button's visibility with the procedure that opens it one of those ways.
 

Robert C

Registered User.
Local time
Today, 13:41
Joined
Mar 27, 2000
Messages
88
AlaskanDad

Thanks for you reply. I'm sorry but my knowledge of VBA is sadly lacking.

How would the line of code read and where in the procedure would it go?

Thanks again, Rob
 

AlaskanDad

Registered User.
Local time
Today, 13:41
Joined
Jun 20, 2000
Messages
39
First, set the Visible Property of the command button on the subform to No. We'll turn it visible only if the form is opened up.

How do you open the form you are talking about? Is it with a command button? If it is, there is VBA code underneath it which tells Access to open up the form. That is where the code would go. It would look like this (change "frmContactsSubFormName" and "YourCommandButton" to make sense):

DoCmd.OpenForm "frmContacts"
Forms!frmContacts!frmContactsSubFormName!Form.YourCommandButton.Visible = True
 

AlaskanDad

Registered User.
Local time
Today, 13:41
Joined
Jun 20, 2000
Messages
39
Sorry, typo.

This is the corrected code:

DoCmd.OpenForm "frmContacts"
Forms!frmContacts!frmContactsSubFormName.Form.YourCommandButton.Visible = True
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:41
Joined
Feb 19, 2002
Messages
43,430
When you open the subform from another form, put some value in the OpenArgs parameter (help will give you the syntax). Then in the subform's load event, check Me.OpenArgs for the value you used in the OpenForm method. If it is not there hide the button.

In the main form, the code to open the report is:
DoCmd.OpenForm "YourFormName",,,,,,"CalledByMainForm"

Of course, if you are currently using any of the parameters I omitted, be sure modify the example to include them.

In the subform's Load event:
...
If Me.OpenArgs = "CalledByMainForm" Then
Me.NameOfYourButton.Visible = True
Else
Me.NameOfYourButton.Visible = False
End If
 

Happytobealive

New member
Local time
Today, 08:41
Joined
Oct 8, 2021
Messages
21
Hi,
I have a continuous subform that loads automatically with the form, and the subform contains a button to open it in a new tab, how can i make that when it opens the button should change to: return to main form?
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:41
Joined
Sep 21, 2011
Messages
14,409
Wow, 21 year old thread, resurrected.
Congrats, you must be the top resurrecter with that post.😀
 

Happytobealive

New member
Local time
Today, 08:41
Joined
Oct 8, 2021
Messages
21
Thank you,
I figured it out:
in the form load i set the visible to true
and in the subform load i set the visible to false.
 

Users who are viewing this thread

Top Bottom