Solved

Limit Combo Box values on  of 2 other Combo Boxes

Posted on 2015-01-20
3
225 Views
Last Modified: 2015-01-20
Small sample db attached.

I have a form "frmRateTool" with multiple Combo Boxes. I am try to set the RowSource of cboFedExServices if the value of 2 other Combo Boxes are "Canada"

Private Sub cboDestinationCountryID_AfterUpdate()

Dim strServiceTypeCanada As String
Dim strServiceClass As String

strServiceClass = "Domestic"

If Me.cboOriginCountryID.Column(1) = "Canada" And Me.cboDestinationCountryID.Column(1) = "Canada" Then

strServiceTypeCanada = "SELECT [tblFedExServices].[ServiceTypeID], [tblFedExServices].[ServiceTypeDescription], " & _
                    "[tblFedExServices].[ServiceClass] WHERE [ServiceClass] = " & Chr$(39) & strServiceClass & Chr$(39)
                   
                                       
                    Me.cboServiceTypeID.RowSource = strServiceTypeCanada
                    Me.cboServiceTypeID.Requery

End If

End Sub
ComboBoxSelection.accdb
0
Comment
Question by:ExpressMan1
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40560296
You're referring to the SECOND column of your combo. The Columns collection for a combo is zero-based.

Are you sure you want to refer to that column?

If instead you want to refer to the FIRST column, then use Column(0).

That said: Your code should work, assuming you've spelled everything correctly, and your "strServiceTypeCanada" statement is formed correctly.

Note too you don't need to Requery cboServiceTypeID. Setting the RowSource is sufficient.
0
 

Author Comment

by:ExpressMan1
ID: 40560386
Column(0) is the ID and Column(1) is the text description of the service. I need the service description to show in the Combo Box.

I am getting the error;

Syntax error (missing operator) in query expression '[tblFedExServices].[ServiceClass] WHERE [ServiceClass] = 'Domestic".

Tried this but no luck;

Dim strServiceTypeCanada As String
Dim strServiceClass As String

strServiceClass = "Domestic"

If Me.cboOriginCountryID.Column(0) = 1 And Me.cboDestinationCountryID.Column(0) = 32 Then

strServiceTypeCanada = "SELECT [tblFedExServices].[ServiceTypeID], [tblFedExServices].[ServiceTypeDescription], " & _
                    "[tblFedExServices].[ServiceClass] WHERE [ServiceClass] =  '" & strServiceClass & "'"
                   
                   
                                       
                    Me.cboServiceTypeID.RowSource = strServiceTypeCanada
0
 

Author Comment

by:ExpressMan1
ID: 40560441
Solved it. Was missing "FROM tblFedEx Services"   !!!

Thank You
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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 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 …

713 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