Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Combobox selection driving another combobox

Posted on 2011-09-08
7
Medium Priority
?
266 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

782 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