Results 1 to 6 of 6

Thread: Could use some VB help with dealing with combo box data from a Union All query

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Oct 2020
    Posts
    4
    Location

    Could use some VB help with dealing with combo box data from a Union All query

    I have a search form with multiple cascading combo boxes. Most combo boxes record sources are linked to a singular table field whereas I am using this code to filter results

    Function SearchCriteria()
        Dim CustomerType As String
        Dim Task As String
        Dim strCriteria As String
        ' Example
        If Not IsNull(Me.cboBathTypes) Then 
            ' Baths
            CustomerType = CustomerType & " And ([BathTypes1] = '" & Me.cboBathTypes & "')"
        End If 
        strCriteria = CustomerType
        Task = "SELECT * FROM qry_Customer where " & strCriteria & " Order by CustomerName asc"
        Me.frm_ExtProducts_Subform1.Form.RecordSource = Task
        Me.frm_ExtProducts_Subform1.Form.Requery
    End Function
    My problem is that I have other combo boxes who's record sources are linked to a Union All query - whereas depending on the selection the data may be coming from [BathTypes1] or [BathTypes2] or [BathTypes3] and I am unable to figure out a working code I have tried so many variations including the following - (does not work)

    If Not IsNull(Me.cboBathTypes) Then 
        ' Baths
        CustomerType = CustomerType & " And ([BathTypes1] = '" & Me.cboBathTypes & "')"
        Else
        CustomerType = CustomerType & " And ([BathTypes2] = '" & Me.cboBathTypes & "')"
        End If
    My experience at coding is very limited and any help in the right direction is much appreciated
    Last edited by Aussiebear; 02-09-2025 at 03:23 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •