Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6017617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:09:17+00:00 2026-05-23T03:09:17+00:00

I have an SQL query with a question(alert like) that pops up every time

  • 0

I have an SQL query with a question(alert like) that pops up every time I open it…

For every value inserted in that question you get diffrent result.

I Want to be able to use that query in my form with a combo-box…

I don’t know how to exceute the query with the parameter from within the form….

I have no problem using VBA, just tell me how to call the query with the parameter

Thanks,
Fingerman

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:09:18+00:00Added an answer on May 23, 2026 at 3:09 am

    I usually use my filtering forms using the following principles:

    1) I first create a query that includes all the fields I want to display and all the fields I want to filter on. It can use more than one table. I do not set any criteria (WHERE clause) in this query unless there is a condition that always needs to be applied no matter what.

    2) Next I create a datasheet form based on this query and I save it, giving it a name that indicates that it’s a subform.

    3) Next I create an unbound main form and add unbound controls such as textboxes, combos, listboxes, checkboxes, etc. that will be used to filter the different fields. One control can potentially allow a user to search on more than one field depending how you write your filtering routine in VBA.

    4) Now it’s time to write code on the main form to make this all work. Basically, the code needs to check to see if there are values in any of the controls and if so, it creates a WHERE clause (without the WHERE keyword) and at the very end it sets the subform’s filter property and turns the subform’s FilterOn property to TRUE.

    Here’s some example code. This was taken from the sample database I’ve made just to demonstrate filtering (see below). This example does not use fuzzy searches (asterisks) and each control on the main form only filters one field on the subform.

    Private Sub cmdFilter_Click()
        'You can also call the FilterSubForm function on a control's AfterUpdate event.
        Call FilterSubform
    End Sub
    
    Private Sub FilterSubform()
    
        Dim strFilter As String
    
        'Note: We have to wrap field names in brackets if they contain spaces or
        'special characters. These fields are in Northwind Traders 2007 from Microsoft
        'I would never consider naming my fields with spaces or special characters
        'in them.
    
        'Company
        If Nz(Me.txtCompany, "") <> "" Then
            strFilter = strFilter & "Company = '" & PQ(Me.txtCompany) & "' And "
        End If
        'First Name
        If Nz(Me.txtFirstName, "") <> "" Then
            strFilter = strFilter & "[First Name] = '" & PQ(Me.txtFirstName) & "' AND "
        End If
        'Last Name
        If Nz(Me.txtLastName, "") <> "" Then
            strFilter = strFilter & "[Last Name] = '" & PQ(Me.txtLastName) & "' AND "
        End If
        'Business Phone
        If Nz(Me.txtBusinessPhone, "") <> "" Then
            strFilter = strFilter & "[Business Phone] = '" & PQ(Me.txtBusinessPhone) & "' AND "
        End If
        'City
        If Nz(Me.cboCity, "") <> "" Then
            strFilter = strFilter & "City = '" & PQ(Me.cboCity) & "' AND "
        End If
        'State/Province
        If Nz(Me.cboStateProvince, "") <> "" Then
            strFilter = strFilter & "[State/Province] = '" & PQ(Me.cboStateProvince) & "' AND "
        End If
        'Order Date
        If Nz(Me.txtOrderDate, "") <> "" Then
            If IsDate(Me.txtOrderDate) = True Then
                strFilter = strFilter & "[Order Date] = #" & Me.txtOrderDate & "# AND "
            End If
        End If
        'Ship Name
        If Nz(Me.txtShipName, "") <> "" Then
            strFilter = strFilter & "[Ship Name] = '" & PQ(Me.txtShipName) & "' AND "
        End If
        'Ship City
        If Nz(Me.txtShipCity, "") <> "" Then
            strFilter = strFilter & "[Ship City] = '" & PQ(Me.txtShipCity) & "' AND "
        End If
        'Ship State/Province
        If Nz(Me.cboShipStateProvince, "") <> "" Then
            strFilter = strFilter & "[Ship State/Province] = '" & PQ(Me.cboShipStateProvince) & "' AND "
        End If
        'Product Code
        If Nz(Me.cboProductCode, "") <> "" Then
            strFilter = strFilter & "[Product Code] = '" & PQ(Me.cboProductCode) & "' AND "
        End If
        'Quantity
        If Nz(Me.txtQuantity, "") <> "" Then
            If IsNumeric(Me.txtQuantity) = True Then
                strFilter = strFilter & "Quantity = " & Me.txtQuantity & " AND "
            End If
        End If
    
        If Right(strFilter, 5) = " AND " Then strFilter = Left(strFilter, Len(strFilter) - 5)
    
        If strFilter <> "" Then
            Me.subformOrderSearch.Form.Filter = strFilter
            Me.subformOrderSearch.Form.FilterOn = True
        Else
                       'Clear the filter
            Me.subformOrderSearch.Form.Filter = ""
            Me.subformOrderSearch.Form.FilterOn = False
        End If
    
    End Sub
    
    Private Function PQ(s As String) As String
        'This function is used to "pad quotes" for SQL  
            PQ = Replace(s, "'", "''")
    End Function
    

    I’ve put together a sample database that has several different examples all building on what I’ve posted here. You can download this database here:
    http://www.utteraccess.com/forum/Search-filtering-Examples-t1968063.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple question. I have an SQL query that looks like
I have a SQL query that takes a very long time to run on
I have a SQL query in my ASP.net web app that looks like this:
I have a sql server query question. I have a table like below. Giving
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I have a sql query that runs super fast, around one second, when not
We have a SQL query that pulls a large number of fields from many
I have a SQL query that is supposed to pull out a record and
I have an SQL query that lists the uid of all users who have
I have an SQL query that executes a LEFT JOIN on another table, then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.