Solved

Access VBA Enable/Disable Form Object

Posted on 2016-09-19
6
71 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
ID: 41805001
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 35

Expert Comment

by:PatHartman
ID: 41805109
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
ID: 41805200
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Closing Comment

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

Author Comment

by:Crxfrd
ID: 41805977
>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)
ID: 41806287
glad to help.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

816 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

7 Experts available now in Live!

Get 1:1 Help Now