Robert C
06-21-2000, 03:39 AM
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
06-21-2000, 06:41 AM
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
06-21-2000, 12:25 PM
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
06-21-2000, 12:37 PM
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.Your CommandButton.Visible = True
AlaskanDad
06-21-2000, 12:40 PM
Sorry, typo.
This is the corrected code:
DoCmd.OpenForm "frmContacts"
Forms!frmContacts!frmContactsSubFormName.Form.Your CommandButton.Visible = True
Pat Hartman
06-21-2000, 12:44 PM
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