Solved

Access VBA Enable/Disable Form Object

Posted on 2016-09-19
6
38 Views
Last Modified: 2016-09-20
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?
0
Comment
Question by:Crxfrd
6 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
Comment Utility
you need to open the form first, then set the Enabled property of the controls on the 2nd form after it is open.  As long as you continue to use acWindowNormal as the window mode, you should be able to simply move the code from lines 10-12 up before line 2.  But I'm not certain why you have the SetWarnings False/True code before and after closing the timer form.

You could also do this in the Open event of the 2nd form, and refer back to the values of controls on form1 to determine which frmInstrument_Time controls should be enabled.
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
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.
0
 
LVL 19

Expert Comment

by:Eric Sherman
Comment Utility
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
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Closing Comment

by:Crxfrd
Comment Utility
Thanks Dale - was trying to tell the form how to behave before it opened
0
 

Author Comment

by:Crxfrd
Comment Utility
>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
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
glad to help.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now