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

Disable a button when the form opens 1

Status
Not open for further replies.

sonikudi

Technical User
Sep 9, 2007
81
US
Hi,

I am using the same form for two purposes. When the user clicks the 'Graph Report' button i want the 'GetGraphDatesStaub' form to open up but to disable the 'Weekly report' Button.

This is what i have for the code in the 'Graph Report' button

Code:
Private Sub Graph_percent_rejected_Click()
OpenForms ("GetGraphDatesStaub")
'Docmd.OpenForm ("GetGraphDatesStaub",acNormal,,,acFormEdit,acWindowNormal)

End Sub

I was trying to use the DoCmd.openForm to find if i can disable the button in the "GetGraphDatesStaub" form. the name of the button i want to disable is 'Weekly_Report'.

Any help will be great.

thanks.
 
So sometimes you want the button disabled, and sometimes you don't? I don't know when you want it enabled, but maybe this will help: You can pass an arguement with OpenArgs (part of the OpenForm statement). So

Docmd.Openform "FormName",,,,,,"From Main Form"

{I don't know the number of commas, just keep going in the statement and it'll show you when OpenArgs is there}


Then in the OnOpen of the next form, check the OpenArgs and perform whatever you need:

Code:
If Me.OpenArgs = "From Main Form" then
    Me.[Weekly_Report].Enabled = false
else
    Me.[Weekly_Report].Enabled = True
end if

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
thanks for suggesting a reply...here is what i am looking for

when i click on the Graph_percent_rejected button (which is in another form, lets just say Form A) i want the "GetGraphDatesStaub" form to open and in this form there is a button called "weekly report"..i want this button to be disabled and i want the opening of the form and the button disabled to happen simultaneously. I tried your code above but it doesn't work. I am not sure what the "From main Form" means exactly..or the purpose of it..

P.S: I have the event code for when this button should be enabled so i simply just want it disabled when i click on the Graph_percent_rejected button
 
Put this code on the button on Form A.
Code:
Private Sub GraphPercentRejected_Click()
    DoCmd.OpenForm "GetGraphDatesStaub", , , , , , "Disable"
    [COLOR=green]'More code here if needed.[/color]
End Sub

Put this code on the GetGraphDatesStaub form.
Code:
Private Sub Form_Open (Cancel As Integer)
    If Me.OpenArgs = "Disable" Then
        Me.WeeklyReport.Enabled = False
    End If
    [COLOR=green]'More code here if needed.[/color]
End Sub


Randy
 
Why then just don't you just set the Enabled Property to NO in the design of the form?

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top