Solved

Access VBA Enable/Disable Form Object

Posted on 2016-09-19
6
59 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 34

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server views 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 Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

911 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

20 Experts available now in Live!

Get 1:1 Help Now