Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Calling Queries from Forms


Message #1 by "James Potter" <questionaccess@h...> on Wed, 15 Jan 2003 15:14:24
Hi there,

I have a problem which I hope someone can help me out with. I am trying to 
run a query which has 2 parameters (Customer name and Date From to Date 
To) from a form. There are three fields on the form where the user may 
input either a customer name or a date range or both. I have a button on 
the form which will be pressed when the data has been inputted into the 
fields. I need some help with the code so that the query runs and gets the 
parameter values from the form.

Thanks in advance,
James
Message #2 by "Wesley Kendrick" <wez.k@n...> on Wed, 15 Jan 2003 17:02:37 -0000
Hi James

Open your query in design mode, then type the full path of the appropriate
field into the criteria row, ie.

Forms!YourFormName!YourFieldName

Then the query will pick up what has been entered in the fields on your form
and use that as its criteria.

Regards, Wesley Kendrick

----- Original Message -----
From: "James Potter" <questionaccess@h...>
To: "Access" <access@p...>
Sent: Wednesday, January 15, 2003 3:14 PM
Subject: [access] Calling Queries from Forms


> Hi there,
>
> I have a problem which I hope someone can help me out with. I am trying to
> run a query which has 2 parameters (Customer name and Date From to Date
> To) from a form. There are three fields on the form where the user may
> input either a customer name or a date range or both. I have a button on
> the form which will be pressed when the data has been inputted into the
> fields. I need some help with the code so that the query runs and gets the
> parameter values from the form.
>
> Thanks in advance,
> James
>

Message #3 by "Derrick Flores" <derrickflores@s...> on Wed, 15 Jan 2003 19:35:18 -0600
James,
This is the way you would reference a field or text box on a form in a
query.  You can place the following
in your criteria section of your query.

[Forms]![FormName]![CustomerName]

Between [Forms]![FormName]![BeginDate] And [Forms]![FormName]![EndDate]

The above works great if you have parameters for them.  If you want to
search for all of the customers for a particular
time frame you would change your criteria to some thing like this.

Like IIF([Forms]![FormName]![CustomerName] = "", "*",
IIF([Forms]![FormName]![CustomerName] = "All",
"*",[Forms]![FormName]![CustomerName]))

You can also check if the dates are available either in your command button
or also in your query.

Between
IIf([Forms]![FormName]![BeginDate]="",Date()-30,[Forms]![FormName]![BeginDat
e])
And
IIf([Forms]![FormName]![EndDate]="",Date(),[Forms]![FormName]![EndDate])

Good Luck,
Derrick Flores
San Antonio, TX

----- Original Message -----
From: "James Potter" <questionaccess@h...>
To: "Access" <access@p...>
Sent: Wednesday, January 15, 2003 3:14 PM
Subject: [access] Calling Queries from Forms


> Hi there,
>
> I have a problem which I hope someone can help me out with. I am trying to
> run a query which has 2 parameters (Customer name and Date From to Date
> To) from a form. There are three fields on the form where the user may
> input either a customer name or a date range or both. I have a button on
> the form which will be pressed when the data has been inputted into the
> fields. I need some help with the code so that the query runs and gets the
> parameter values from the form.
>
> Thanks in advance,
> James


  Return to Index