error in entering variables

swarv

Registered User.
Local time
Today, 02:04
Joined
Dec 2, 2008
Messages
196
Hi all

I have the following code

Code:
DoCmd.OpenReport "absent2", acViewPreview, , "Start_Date > [enter first date] and Start_Date < [enter last date]"

How can I change [enter first date] and [enter last date] into preentered variables.

i.e.

adate = txtstartdate
bdate = txtenddate

then:

DoCmd.OpenReport "absent2", acViewPreview, , "Start_Date > adate and Start_Date < bdate"

but it doesn't work

cheers
 
Move the parameters out of your query, if that's where they are and use the form controls to parse the sql.

Code:
strCondition = "[Start_Date]  Between #" & Me.StartDate & "# And #" Me.EndDate & "#"

DoCmd.OpenReport "absent2", acViewPreview, , strCondition
 
hi,

many thanks for that.

I now have the following code:


strcondition = "[Start_Date] BETWEEN #" & Me.txtstartdate & "# AND #" & Me.txtEndDate & "#"

DoCmd.OpenReport "absent2", acViewPreview, , strcondition

but for some reason it still doesn't display anything in the report.

Any ideas would be great?

thanks
 
If you take out the condition does it display data?

Is there actually any data in the date range you have selected. Don't forget it may be reversing the dates from dd/mm/yyyy to mm/dd/yyyy or vice versa.

Steps to test
Debug.print the strcondition
copy the string from the immediate window
design you underlying query
insert the string under the appropriate column
open in datasheet view

Do you see any data?
 
ok - I think it is reversing the dates. ergh. cheers for you help. I'll just make a note of it to enter the dates in the other way round. cheers
 

Users who are viewing this thread

Back
Top Bottom