Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002

    Unanswered: Query with variable in a form

    I made a query using a variable. So when I just run the query it gives an input box where I can set the value for it.

    But I need it for something else. I've made a form with a text box and there I want to show the result of that query. The variable he needs is located on the same form. But how do I get the query to take that variable and not give an inputbox?

  2. #2
    Join Date
    Jul 2002
    OK 2 part answer to this

    1) Reference the textbox on the form in the query criteria QBE grid as "[Forms]![textboxname]

    2) However a much better way of doing this is to first use string concatenation to build a querystring and then execute that string you have created (or change the sql of the query you want to open to the text of the string) e.g.

    dim strSQL as string
    dim db as database

    strSQL = "SELECT * FROM tblEmployers WHERE Surname = '" & me.txtbox.value & "'"

    DO NOT FORGET the ' (single quote) which warns the query there is text coming up (see either side of the break in the string)

    and then either

    db.querydefs("MyQuery").sql = strsql

    and open the query as normal


    db.createquerydef("",strsql).execute for action queries

    If you use the second method you will avoid a lot of pitfalls later on with "parameter query" errors

    It also looks alot better to the end user doing it the 2nd way

    Hope that helps


  3. #3
    Join Date
    Jul 2002
    Sorry part 1 should read:

    1) Reference the textbox on the form in the query criteria QBE grid as "[Forms]![formname]![textboxname]

Posting Permissions

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