Link to home
Start Free TrialLog in
Avatar of Gary Croxford
Gary CroxfordFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access VBA Enable/Disable Form Object

Thank you for looking at my question,

I have a button on a form (cmdTimeForm) that when clicked will open a second form (frmInstrumentTime) for the user to make a further selection about the data to be displayed in a report.

The second form has a range of options organised in option frames and I want only those frames that are pertinent to the selections made on the first form to be enabled.

The code I have so far is below:

Private Sub cmdTimeForm_Click()
    frmInstrument_Time.frame1000.Enabled = True
    frmInstrument_Time.frame2000.Enabled = False
    frmInstrument_Time.frame3000.Enabled = False
    frmInstrument_Time.frame4000.Enabled = False
    frmInstrument_Time.frame6000.Enabled = False
    frmInstrument_Time.frame7000_1.Enabled = False
    frmInstrument_Time.frame7000_2.Enabled = False
    
    DoCmd.SetWarnings False
    DoCmd.OpenForm "frmInstrument_Time", acNormal, , , acFormEdit, acWindowNormal
    docdm.SetWarnings True
End Sub

Open in new window


When I click the button the code falls over with error 424 - Object Required

Please, how do I enable / disable the relevant option groups in the buttons OnClick event before the second form opens?
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As Dale said, you cannot alter the form's properties BEFORE you open it.

I don't see any conditional statement that is setting the enabled property based on anything.  You said you want this to be conditional.  So, what determines what option groups should be enabled?  Based on what I see, you are always enabling/disabling the frames without any condition.


PS -  Good practice is to give your controls meaningful names.  frame1000 is meaningless.
Here is a sample of how I accomplish what you are asking.  I have a Dispatch reporting form with approximately 50 plus reports that can be selected along with a ton of parameters that are unique to each report.  Therefore, I turn off certain parameters based on the report that is currently selected.

Just follow the steps below and let me know if you have any additional questions.

1.) Create a ReportsTbl with the following fields
REPORT_VALUE, REPORT_NAME, REPORT_DESCRIPTION, PARAM_PROPERTY_ID, PARAM_DATE, PARAM_ACCOUNT, PARAM_ROUTE  -  Make the PARAM fields True/False fields.

2.) Assign each report a unique numerical REPORT_VALUE and set the appropriate PARAM fields to TRUE for each report.

3.) Create a ListBox using the REPORT_NAME and REPORT_VALUE fields from your ReportsTbl. Make the REPORT_VALUE the Bound field for the list box.

4.) Place this ListBox on the same Form Object as your parameters the user selects for the report.

5.) Using the AfterUpdate Event of your ListBox you can then Enable or Disable the report parameters as shown below.

Me.TxtPARAM_PROPERTY_ID.Enabled = DLookup("PARAM_PROPERTY_ID", "ReportsTbl", "[Report_Value] = " & Me.ListBox)

Me.TxtPARAM_DATE.Enabled = DLookup("PARAM_DATE", "ReportsTbl", "[Report_Value] = " & Me.ListBox)

Me.TxtPARAM_ACCOUNT.Enabled = DLookup("PARAM_ACCOUNT", "ReportsTbl", "[Report_Value] = " & Me.ListBox)

Me.TxtPARAM_ROUTE.Enabled = DLookup("PARAM_ROUTE", "ReportsTbl", "[Report_Value] = " & Me.ListBox)

You would print the report by name from the table based on the report value in your Listbox.

This works and is easy to control/maintain as you add additional reports.

ET
Avatar of Gary Croxford

ASKER

Thanks Dale - was trying to tell the form how to behave before it opened
>PatHartman

frame1000 is an option group relating to the 1000 product series, frame200 relates the 2000 product series - see where I'm going with this?

Thank you again for looking at my question
glad to help.