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

x
?
Solved

Combobox selection driving another combobox

Posted on 2011-09-08
7
Medium Priority
?
264 Views
Last Modified: 2012-05-12
Hi im using the following code which should basically only make Combo2 visible if Combo1's selection is not "insurance".  This code is on the AfterUpdate but does not work can someone point out where im going wrong?  Cheers    

Also could I add some code which drives the values that are available in Combo2's dropdown based on the User Selection in Combo1.

    If Combo1.value = "Insurance" Then
        Combo2.Visible = False
    Else
        Combo2.Visible = True
    End If
0
Comment
Question by:JSSenior
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 668 total points
ID: 36501856
In most cases, you must refer to the correct Column in your combo's rowsource. For example:

If Combo1.Column(1) = "Insurance" Then
  Combo2.Visible = False
Else
  Combo2.Visible = True
End If

BTW, a quicker way to write this is:

Combo2.Visible = (Combo1.Column(1) = "Insurance")

Note too that the Column collection of a Combo is zero-based, so Column(1) is the SECOND column in the combo's Rowsource.
0
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 668 total points
ID: 36501858
You need to check the number of columns in combo1- if you have created it using the wizard then you might have a hidden ID column which is the true value of the combo.

To get combo2 to reflect the value in combo1, you need to set the rowsource of combo2.

On way to do this is to use the combo1 afterupdate event and do something like this for a number value for combo1...

Me.combo2.rowsource = "Select field1, field2 from table where fieldx = " & me.combo1

or  for a text value for combo1
Me.combo2.rowsource = "Select field1, field2 from table where fieldx = '" & me.combo1 & "'"
 
0
 
LVL 85
ID: 36501863
Forgot to mention:

Most UI experts agree that hiding/showing controls based on user selections is confusing and disconcerting to users. You are generally far better off enabling or disabling controls in those instancees. The exception to this would be if a control should only be shown to specific "groups" - for example, members of a Managers Group should be able to see ButtonA, but no one else should see that button. In those cases it's fine to hid controls.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JSSenior
ID: 36501940
Great that works, thank you.  How about the second part of the question can I also drive the list of values that will be available in the dropdown on Combo2 depending on the value in Combo1?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36501986
Pete's solution should answer that...
http:#a36501858
0
 

Author Comment

by:JSSenior
ID: 36502030
Hi points value increased as my question had two parts.

As there is only a few options could I just list them in the VBA code?



0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 664 total points
ID: 36502148
You would have to make the rowsource type Value List:

me.YourCombo.RowSourceType= "Value List"
If somecondition = true then
       me.YourCombo.rowsource = "a;b;c"
else
       me.YourCombo.rowsource = "1;2;3"
end if

Open in new window

     
0

Featured Post

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.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

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