Consulting

Results 1 to 8 of 8

Thread: Solved: forms and queries

  1. #1
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location

    Solved: forms and queries

    Is it possible to create a form that will allow a user to perform their own queries? Basically I need some type of form where the user just clicks on certain criteria and performs queires and is able to present those results in a report. any suggestions?

  2. #2
    You can create a query to reference user input from a form's controls. So as long as the tables, join relationships, and selected fields are always the same, you can save a single query that can change depending on the user's input.

    For example, say your form is named "frmSelectReport", which has a textbox named "txtLastName" where the user can specify which last name to search for. In your saved query, you would place the line [Forms]![frmSelectReport]![txtLastName] (with all brackets) in the Criteria box for the last name field. Then whenever the query is executed (whether by itself or for a form or report), it will use the value of the txtLastName textbox (provided that the form is opened) as its criteria.

  3. #3
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    Quote Originally Posted by chocobochick
    You can create a query to reference user input from a form's controls. So as long as the tables, join relationships, and selected fields are always the same, you can save a single query that can change depending on the user's input.

    For example, say your form is named "frmSelectReport", which has a textbox named "txtLastName" where the user can specify which last name to search for. In your saved query, you would place the line [Forms]![frmSelectReport]![txtLastName] (with all brackets) in the Criteria box for the last name field. Then whenever the query is executed (whether by itself or for a form or report), it will use the value of the txtLastName textbox (provided that the form is opened) as its criteria.
    One more question. I get the following error message when I try and run my parameter query:

    Invalid bracketing of name'[Forms]![Query]![StartDate] And [Forms]![Query]![EndDate]'.

    Any suggestions?
    Thanks for your help.

  4. #4
    You named your form "Query"? Try renaming it to something that might not be misinterpreted as a special keyword. I personally use the naming convention in which each form starts with the letters "frm", so in a case like this I might name it "frmUserQuery" or something similar.

    Let me know if that doesn't solve the problem.

  5. #5
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    Quote Originally Posted by chocobochick
    You named your form "Query"? Try renaming it to something that might not be misinterpreted as a special keyword. I personally use the naming convention in which each form starts with the letters "frm", so in a case like this I might name it "frmUserQuery" or something similar.

    Let me know if that doesn't solve the problem.
    I renamed it to Results and I still get the same error message.

  6. #6
    That's an odd error. What version of Access are you using? What's the exact expression (all punctuation included) entered into your criteria box?

  7. #7
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    Quote Originally Posted by chocobochick
    That's an odd error. What version of Access are you using? What's the exact expression (all punctuation included) entered into your criteria box?
    It should be:

     
    PARAMETERS [Forms]![Results]![CompanyName] Text ( 255 ), [Forms]![Results]![StartDate] DateTime, [Forms]![Results]![EndDate] DateTime;
    as The operators Between and AND are not included in the parameter. It works fine now.

    Thank you for your help!!!

  8. #8
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    Goldie, if this is solved, would you mind using the Thread Tools at the top of this page to mark it solved? Thanks.

Posting Permissions

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