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

Access VBA Hiding Button when opening a sub form - Help 1

Status
Not open for further replies.

PSBA11

MIS
Jul 18, 2011
12
0
0
GB
Hi,

I'm fairly new to access but I'll try to explain my problem as best I can.

I have a main form, which includes a switchable subform (When a button is pressed on the main form, a different subform will appear)

one subform is called "SubFrm_My_Actions" It brings up a list of all the actions, and a button on the subform to add new actions. This subform can be opened via other forms as well as the main one.

What I need to do is hide the "Add New Actions" button when the Subform is opened Via the Main Form. Any help on this would be greatly appreciated.
 
I've been trying that but that hides the button from the whole subform, I only want to hide it when it is accessed via the Main Form.
 
In the Load event procedure of the subform:
Me![Add New Actions].Visible = Not CurrentProject.AllForms("your main form").IsLoaded

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I put this in the Load event and it still erased the button from the whole subform, regardless of where you access it.

Private Sub Form_Load()
Chk_Due_Actions.Value = DLookup("Default_Value", "SysTbl_Settings", "Control = ""Chk_Due_Actions""")
Chk_My_Actions.Value = DLookup("Default_Value", "SysTbl_Settings", "Control = ""Chk_My_Actions""")
Chk_Open_Actions.Value = DLookup("Default_Value", "SysTbl_Settings", "Control = ""Chk_Open_Actions""")
Me![Cmd_Add_Action].Visible = Not CurrentProject.AllForms(Frm_Main).IsLoaded
Filter_SubFrm_My_Actions Me.Parent.Name, "SubFrm_Switchable"
Me![Cmd_Add_Action].Visible = Not CurrentProject.AllForms("Frm_Main").IsLoaded
End Sub


This subform can be access through the MAIN form, CUSTOMER form, MEETINGS form & OPPORTUNITIES form. The last 3 need that button in order to create actions.
 
Replace this:
Me![Cmd_Add_Action].Visible = Not CurrentProject.AllForms(Frm_Main).IsLoaded
with this:
Me![Cmd_Add_Action].Visible = Not CurrentProject.AllForms("MAIN").IsLoaded

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have done this and am now getting the following message

"The expression you entered refers to an object that is closed or doesn't exist."

The Main form is open when it runs. Is this because I have replaced it with MAIN? Because the name of the form is Frm_Main
 
So, try this:
Me![Cmd_Add_Action].Visible = Not CurrentProject.AllForms("Frm_Main").IsLoaded

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That's what I tried and it removed the button from the subform regardless of how I navigate to it.
 
I've solved the problem now.

I put an IF function around it.

If Me.Parent.Name = "Frm_Main" Then
Me![Cmd_Add_Action].Visible = Not CurrentProject.AllForms("Frm_Main").IsLoaded
End If


Thank you for your help, been struggling with this all day!!
 
I was mistaken and this has not solved the problem. If anyone is able to help me that would be greatly appreciated.
 
What about this in the Current event procedure of the subform ?
Me![Cmd_Add_Action].Visible = Not (Me.Parent.Name = "Frm_Main")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya PSBA11 . . .

Is [blue]SubFrm_My_Actions[/blue] a true subform with [blue]master/child[/blue] link properties, or is it a form [blue]opened independently[/blue] and your calling it a subform?

The above will change how you reference the button!

[blue]Your Thoughts? . . .[/blue]


See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
PHV this is now working perfectly thank you very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top