Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to change combo box data on a subform when a certain selection is made from a combo box on a main form

Posted on 2011-02-21
15
Medium Priority
?
496 Views
Last Modified: 2012-05-11
I have a form1 (frmEmployee_Audits)  that has a subform (frmQuality_Review_Subform).  There is a combo box (cboRegion) on form1 (frmEmployee_Audits) that if the user chooses "East" that the combo box (cboQualRevCriteria) on the subform (frmQuality_Review_Subform) should change to a specific listing that is in a table called "tblCode_East", otherwise it should change the combo box on the subform to list the data in a table called "tblCode_West".

I have posted my code below in the Code box.  When I run my code I get an error saying that it can't find the form "frmQuality_Review_Subform" referred to in a macro expression or Visual Basic Code, and the combo box dropdown(cboQualRevCriteria) on the subform (frmQuality_Review_Subform) is blank.

I have the code on the Deactivate Event Procedure.

What am I doing wrong?

Thanks,

gdunn59
Private Sub Form_Deactivate()
    If Me.Region = "East" Then
        Forms!frmQuality_Review_Subform!cboQualRevCriteria.SetFocus
        Forms!frmQuality_Review_Subform!cboQualRevCriteria = "Combo Box"
        Forms!frmQuality_Review_Subform!cboQualRevCriteria.RowSource = "select * from tblCode_East"
        Forms!frmQuality_Review_Subform!cboQualRevCriteria.Requery
    Else
        Forms!frmQuality_Review_Subform!cboQualRevCriteria.RowSource = "select * from tblCode_West"
        Forms!frmQuality_Review_Subform!cboQualRevCriteria.Requery
    End If
    
End Sub

Open in new window

0
Comment
Question by:gdunn59
[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
  • 9
  • 6
15 Comments
 
LVL 1

Author Comment

by:gdunn59
ID: 34946508
Meant to say on a subform, not on a "second from" in the Title.

Thanks,
gdunn59
0
 
LVL 1

Author Comment

by:gdunn59
ID: 34946528
It is on the Deactivate Event Procedure of form1 (frmEmployee_Audits).

Forgot to state that.

Thanks,
gdunn59
0
 
LVL 3

Expert Comment

by:DockieBoy
ID: 34946676
Your subform is effectively a control on your main form.

Me.[subform_name].Form.[control_name] =
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 3

Expert Comment

by:DockieBoy
ID: 34946702
Sorry, I should clarify that.  "[subform_name]" is not the name of your sub form, it is the name of the control on your form that holds the sub form.  :)

"[control_name]" is the name of the control on your sub form.  
0
 
LVL 1

Author Comment

by:gdunn59
ID: 34946732
Ok, I'm still a little confused.  I need the subform control_name "cboQualRevCriteria (combo box dropdown) list to change depending on what the user chooses in the main form (frmEmployee_Audits) control_name "cboRegion (combo box dropdown) list.

Thanks,
gdunn59
0
 
LVL 3

Expert Comment

by:DockieBoy
ID: 34946770
On your main form in design view, make sure that the sub form is not selected, then right click on the sub form, select properties, click on the "all" tab and at the very top of that list, tell me what the name is.  :)
0
 
LVL 1

Author Comment

by:gdunn59
ID: 34946785
It is:

frmQuality_Review_Subform
0
 
LVL 3

Expert Comment

by:DockieBoy
ID: 34946797
Sorry, I also need to clarify what "Me.Region" is that you refer to in your code.  Is that a text box that has the value of the combo box "cboRegion" in it?
0
 
LVL 1

Author Comment

by:gdunn59
ID: 34946838
Not it is a separate combo box on the subform.  That is the combo box that I need to change the data that appears in that combo box depending on what the user chooses from the combo box cboRegion on the main form.
0
 
LVL 1

Author Comment

by:gdunn59
ID: 34946845
Sorry not on the subform, but on the main form.
0
 
LVL 1

Author Comment

by:gdunn59
ID: 34946867
Please let me clarify.

The cboRegion combo box is on the main form (frmEmployee_Audits).

Depending on what the user chooses in this cboRegion combo box on the main form (frmEmployee_Audits), I need the combo box (cboQualRevCriteria) on the subform (frmQuality_Review_Subform) to change based off of what was chosen in the cboRegion combo box on the main form (frmEmployee_Audits).

Hope this makes sense and I'm not confusing you too much!

Thanks,
gdunn59
0
 
LVL 3

Accepted Solution

by:
DockieBoy earned 1000 total points
ID: 34946944
Ok, cool, try this then.

Private Sub cboRegion_Change()
Dim MyString As String
 Select Case Me.cboRegion.Text
  Case "East"
   MyString = "select * from tblCode_East;"
   Me.frmQuality_Review_Subform.Form.cboQualRevCriteria.RowSource = MyString
   Me.frmQuality_Review_Subform.Form.cboQualRevCriteria.Requery
  Case "West"
   MyString = "select * from tblCode_West;"
   Me.frmQuality_Review_Subform.Form.cboQualRevCriteria.RowSource = MyString
   Me.frmQuality_Review_Subform.Form.cboQualRevCriteria.Requery
  Case Else
   MsgBox "Subform Can Not Be Updated From This Value"
 End Select
End Sub

This will update the combo on the sub form when the user changes the selection in the combo on the main form.  

The code is for the on change event of the combo "cboRegion"  on the main form

Sorry, I haven't tested this, so let me know how you go.  :)
0
 
LVL 1

Author Comment

by:gdunn59
ID: 34946983
Great, that worked!

You're wonderful.

I will accept the last solution you provided.

Thanks much,
gdunn59
0
 
LVL 1

Author Closing Comment

by:gdunn59
ID: 34946990
Works like a charm.

Thanks much!
0
 
LVL 3

Expert Comment

by:DockieBoy
ID: 34947003
Happy to help  :)
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

730 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