?
Solved

Access VBA Enable/Disable Form Object

Posted on 2016-09-19
6
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 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 38

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 48

Expert Comment

by:Dale Fye
ID: 41806287
glad to help.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

770 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