code to make new query with criteria

G

Guest

Hi eveyone.

I have a form based on a query with the following fields:

No Company Agreeementdate

what i need is a code so the user can enter a range of dates (01-Jan-2004 to
30-Jan-2004) and have those records copied in a new query.

Any ideas?

thanks
 
E

Eric

Your code should look something like this:

Dim datStart, datEnd as Date
Dim strCriteria as String
datStart = InputBox("Start date:")
datEnd = InputBox("End date:")
strCriteria = "(([AgreementDate] >= #" & CDate(datStart)
& "#) And ([AgreementDate] <= #" & CDate(datEnd) & "#))"
Docmd.Close
Docmd.OpenForm "<form name>",,strCriteria

An easier way is to just put criteria in the form's
underlying query grid. But you asked for code...
 
G

Guest

Hi Erik thank for you rhelp, but i have a little problem.

I have entered that code into a togle buttoninto my form,
then apperar the 2 input boxes asking me for the date, and then it seems to
open the same form i am working with...

Just to clarify....
No Company Agreeementdate
1 abc 01-Jan-2004
2 def 15-feb-2004
3 ghi 25-feb-2004
4 jkl 30-mar-2004

i have these data filled in a Query, what i would need is let's say have the
name and the date of the companies withthe date of february copied in a new
query.
is tha possible?

thanks a lot for your help. (sorry if i am giving you a headache)


Eric said:
Your code should look something like this:

Dim datStart, datEnd as Date
Dim strCriteria as String
datStart = InputBox("Start date:")
datEnd = InputBox("End date:")
strCriteria = "(([AgreementDate] >= #" & CDate(datStart)
& "#) And ([AgreementDate] <= #" & CDate(datEnd) & "#))"
Docmd.Close
Docmd.OpenForm "<form name>",,strCriteria

An easier way is to just put criteria in the form's
underlying query grid. But you asked for code...
-----Original Message-----
Hi eveyone.

I have a form based on a query with the following fields:

No Company Agreeementdate

what i need is a code so the user can enter a range of dates (01-Jan-2004 to
30-Jan-2004) and have those records copied in a new query.

Any ideas?

thanks
.
 
G

Guest

Too complicated?
i'll try to explain again...
i have this data filled in a query using a form:

No Company Agreeementdate
1 abc 01-Jan-2004
2 def 15-feb-2004
3 ghi 25-feb-2004
4 jkl 30-mar-2004

what i would need is a code so the user can select the data from an
especific time (lets say from 01-feb-2004 to 28-feb-2004) and i want the
records that match the time copied in a completely new query so i can export
that data to excel (in thse case only record No 2 and No 3)

thansk a lot for your patience
 
J

John Vinson

Too complicated?
i'll try to explain again...
i have this data filled in a query using a form:

No Company Agreeementdate
1 abc 01-Jan-2004
2 def 15-feb-2004
3 ghi 25-feb-2004
4 jkl 30-mar-2004

what i would need is a code so the user can select the data from an
especific time (lets say from 01-feb-2004 to 28-feb-2004) and i want the
records that match the time copied in a completely new query so i can export
that data to excel (in thse case only record No 2 and No 3)


Create a Query based on the table (or on the query). Select the three
fields.

Put a criterion on the [Agreement Date] field of

BETWEEN #2/1/2004# AND #2/28/2004#

or, better,

BETWEEN [Enter start date:] AND [Enter end date:]

Use this query as the basis for your export.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top