Results 1 to 13 of 13
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,095

    How does one filter the RowSource of a combo box


    I don't see a "Filter" qualifier in the properties of a combo box for either of ControlSource OR RowSource. So, how does one filter the data for a combo box?

    As it is now, the RowSource is a saved query. I'd like NOT to have the RowSource specified as a fully expressed SQL expression.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Then you will have to put filter parameters in the query object.

    Or make the RowSource an SQL statement that pulls from the query object.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,095
    Then you will have to put filter parameters in the query object.
    That's a new one for me. How do I do that?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    How can this be new? It is basic to building queries. Open query in design view and put parameters in the Criteria row.

    Exactly what to do you want to base the filtering on?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,095
    I just don't know how to change the criteria from code.

    The query I started with: (QFreqUsed)
    Click image for larger version. 

Name:	QFreqUsed.jpg 
Views:	10 
Size:	27.9 KB 
ID:	23363

    What I'm trying to get to without having to express the SQL in code:
    Code:
    Select Case intNewTTypeID
        Case 6, 7
            Me.cboDescriptions.RowSource = "SELECT * FROM tblFreqUsed WHERE (((FreqU)=True) AND (TypeFltrID )= 67) ORDER BY Description;"
        Case 16
            Me.cboDescriptions.RowSource = "SELECT * FROM tblFreqUsed WHERE (((FreqU)=True) AND (TypeFltrID )= 16) ORDER BY Description;"
        Case Else
            Me.cboDescriptions.RowSource = "SELECT * FROM tblFreqUsed WHERE (((FreqU)=True) AND (TypeFltrID )= 0) ORDER BY Description;"
    End Select

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That code should change the RowSource.

    Then need:

    Me.cboDescription.Requery


    What is intNewTTypeID based on? Since the criteria is dependent on value of this variable, how can you avoid VBA?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,095
    Sorry June, I think my failure to better describe the issue has caused nothing but confusion. I started with the combo control property RowSource = QFreqUsed. As development progressed, I came up with a user requested modification to limit the content of the combo based on the current functional condition of the app. With that, I wanted to filter the RowSource of the combo. Something more like:

    Code:
    Private Sub tbNewDescription_DblClick(Cancel As Integer)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Descriptions to come from list based on type of transaction.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Select Case intNewTTypeID
        Case 6, 7
            Me.cboDescriptions.RowSource = QFreqUsed "TypeFltrID = 67"
    
        Case Is > 50     ' Values greater than 50 are translations from base 16
            Me.cboDescriptions.RowSource = QFreqUsed "TypeFltrID = 16"
    
        Case Else
            Me.cboDescriptions.RowSource = QFreqUsed "TypeFltrID = 0"
    End Select
    
    Me.cboDescriptions.Visible = True
    Me.cboDescriptions.SetFocus
    Me.cboDescriptions.Dropdown
    
    End Sub
    Since I'd never had the occasion to dynamically change criteria to a RowSource query in code OTHER than with SQL as posted earlier, I thought I'd ask my true friends at the forum.

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,095
    I'll just go with this:
    Code:
    Private Sub tbNewDescription_DblClick(Cancel As Integer)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim intTempID As Integer
    Select Case intNewTTypeID
        Case 6, 7
            intTempID = 67
        Case Is > 50     'It will be a check number if greater than 50
            intTempID = 16
        Case Else
            intTempID = 0
    End Select
            
    Me.cboDescriptions.RowSource = "SELECT * FROM tblFreqUsed WHERE (((FreqU)=True) AND (TypeFltrID )= " & _
                                   intTempid & ") ORDER BY Description;"
    Me.cboDescriptions.Visible = True
    Me.cboDescriptions.SetFocus
    Me.cboDescriptions.Dropdown
    
    End Sub

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What does 'current functional condition of the app' mean? You want to filter the combobox based on some value in record on the form?

    So again, what is intNewTTypeID based on? Is this a VBA variable or a field name? If this is a VBA variable, should it be set to value from a field of the form current record? Because your code does not now set value of intNewTTypeID, therefore will always flow to the Case Else.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I still don't know what intNewTTypeID is nor how it gets a value.

    Have you tested code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,095
    Not sure how to answer your question other than to say that intNewTTypeID is a VBA variable that is set according to a transaction type choice the user makes. That choice is what creates the condition or state from which another dropdown choice the user makes about a description of the transaction.

    This is a very robust app primarily centered around a single form behind which are 1216 lines of VBA code. The segment I posted is the sub that in part processes the additional user actions pertaining to choices about transaction descriptions. The latter is where the combo box is employed and where the new functionality came about where the choices presented are limited depending on the transaction type, i.e., the VBA variable intNewTTypeID.

    The code posted in #8 works perfectly and why I marked the issue resolved.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    intNewTTypeID is not declared nor set in the procedure you posted. So I presume this is a public variable declared and set elsewhere.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,095
    intNewTTypeID is global to the form's module and is set elsewhere.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 09-03-2015, 11:12 AM
  2. Combo box that filters the rowsource
    By billcar2006 in forum Access
    Replies: 3
    Last Post: 02-26-2015, 08:05 PM
  3. Replies: 1
    Last Post: 10-01-2013, 09:25 PM
  4. Replies: 2
    Last Post: 09-14-2012, 04:40 PM
  5. .RowSource Combo
    By white_flag in forum Access
    Replies: 1
    Last Post: 09-06-2011, 07:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums