Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2004
    Location
    Cinci, OH
    Posts
    49

    Unanswered: query from fields on a form

    Hey all,

    I have created a simple query that selects all fields from tblMain.

    I have also created a form with a cmbname, txtstartdate, and txtenddate fields.

    What I want to do is have the user select the name from the cmbName, enter a start date and date. then click on the button that will use the selected/entered info from the field to run the query. The user's entered info will be used as the criteria for the query.

    Can someone please give a easy example of code to use or is there a neat click trick in access that allows me to do this?

    thanks in advance for the help.

    Thanks.
    Richard.

  2. #2
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    There are many ways to do this, depending on what you want to happen next (printed report, export to Excel, view or edit of results on screen).

    A good start would be to make the query the recordsource of the form, add the fields to the form and in your command button set the form's filter and turn it on.

    The things to lookup are:
    Me.Filter = "[Field A] = Something"
    Me.FilterOn True

    good luck,
    tc

  3. #3
    Join Date
    Aug 2004
    Location
    Cinci, OH
    Posts
    49
    My goal is to print a report from the query that is run off the form.

  4. #4
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    ok, so modify my first post slightly: leave off the data from the table on the form. Instead of using the form filter, use DoCmd.OpenReport and look closely at the "Where Clause" (which, consequently, will be identical to the "Filter" for the form).

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Printing a report based on values

    Maybe this will help you in the direction you're going (see attachment as an example of putting selection criteria on a form and then opening a report based on that criteria).
    Attached Files Attached Files
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Aug 2004
    Location
    Cinci, OH
    Posts
    49
    thanks very much. That helps alot.

    Richard.

Posting Permissions

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