Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2002

    Unanswered: Building a Criteria for a Query from a form.

    I have yet another question. This is the situation, we have three text boxes on a form. And we would like to create one query to pull data from these text boxes. The problem is that we need the query to be dynamic. Meaning when the program is running and the query is ran, sometimes only one textbox is used for the query. Other times all three or just two of the text boxes is used for the query. Is there way to build the criteria for that one query to select information from the desired textboxes and not just all three of them every time. For example it would be nice to coordinate it with an if statement.

    If value = true then
    Build the criteria to except data from one text box
    Build the criteria to except data from two text boxes
    end if

    It all boils down to this one simple question. Is it possible to build criteria for a query within a form’s code? Any help that anyone can give will be very much appreciated.

  2. #2
    Join Date
    Oct 2001
    Bay Area, CA
    First see if you can solve this directly with your query without using code. Consider this example.

    SELECT Name1,Name2,Name3 FROM tblNames
    HAVING (Name1 Like "*" & [Forms]![frmMain]![txtName1] And Name2 Like "*" & [Forms]![frmMain]![txtName2] And Name3 Like "*" & [Forms]![frmMain]![txtName3])

    This query will allow you to have no value in your text box, in this case the filter value is wild (*), or it will have *(Name) as the filter value.

    If this doesn't work, there are other solutions, with if statements, or code.

    Hope this helps...

Posting Permissions

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