wordpress statistics
  • Today is Friday, May 18, 2012

3 Responses to “Selected List Box Items and Dynamic Query”

  1. Björn says:

    Hi

    Hope you can help me, I have a combo box on a form wich filters data depending on information in a text box. This works fine, but i need to give the user a possibility to check a box that says unfilter to show all data instead of filtered data. I have tried for probably 8-10 hours now, and i give up :)

    Regards

    Bjorn

  2. Hi,

    Since, you are using a Text Box to set the criteria to filter data in the ComboBox you can use the same Text Box to remove the filter as well.

    When you set some value into the Text Box and leave out of the Text Box (Lost Focus Event) the Combo Box uses the Data in the Text (if available) to filter the Combobox contents or if the Text Box is empty then the ComboBox wil show the entire Source data.

    This can be done by evaluating the text box contents and build an SQL String and change the Row Source Property of the Combobox and Requery the Combobox contents.

    The sample code is given below, which uses the Order Details file from Northwind.mdb database:

    Private Sub Criteria_LostFocus()
    Dim xOrderID, SQL As String

    xOrderID = Nz(Me![Criteria], 0)
    If xOrderID = 0 Then
    SQL = "SELECT [ORDER DETAILS].* FROM [ORDER DETAILS];"
    Else
    SQL = "SELECT [ORDER DETAILS].* FROM [ORDER DETAILS] WHERE ((ORDERID=" & xOrderID & "));"
    End If
    Me.cboOrder.RowSource = SQL
    Me.cboOrder.Requery

    End Sub

    I have used the TextBox Name as Criteria and ComboBox Name as cboOrderin the Code.

    Regards,
    a.p.r. pillai

  3. Björn says:

    Hi

    It worked! After that i did som thinking and created a button instead to call the event to show all data unfiltered, it seems to be more logical for the user instad of a checkbox.

    Thanks alot for your help!

    Regards

    Björn

Leave a Reply

You must be logged in to post a comment.