Expression builder in a Form

J

Johnwats

I am setting up a database for students on a course. I want to work out how
long students are taking on the course. In a form i have a start date, then
i have used expression builder to find number of days between the start date
& current date. That worked OK. But at some point i will be entering an end
date to the course. How do i change the expression so that it "stops" at the
end date(when entered), rather than keep on calculating to the current date?
I want the expression to somehow compare the calculated date to the end date
& use whichever is the less, but i am completely stuck.

Using Access 2000 in my first attempt at a database. Any help appreciated.
 
K

Klatuu

You could use and IIf statement for this:

=DateDiff("d",[StartDate], IIf(Date<[EndDate],Date,[EndDAte))
 
J

Johnwats

Thanks for the reply. I couldn't get it to work, got an error #Name. Is the
current date in your example, i am afraid i can't understand the syntax.
--
Johnwats


Klatuu said:
You could use and IIf statement for this:

=DateDiff("d",[StartDate], IIf(Date<[EndDate],Date,[EndDAte))
--
Dave Hargis, Microsoft Access MVP


Johnwats said:
I am setting up a database for students on a course. I want to work out how
long students are taking on the course. In a form i have a start date, then
i have used expression builder to find number of days between the start date
& current date. That worked OK. But at some point i will be entering an end
date to the course. How do i change the expression so that it "stops" at the
end date(when entered), rather than keep on calculating to the current date?
I want the expression to somehow compare the calculated date to the end date
& use whichever is the less, but i am completely stuck.

Using Access 2000 in my first attempt at a database. Any help appreciated.
 
K

Klatuu

Well, for starters, I left off a closing bracket: v
=DateDiff("d",[StartDate], IIf(Date<[EndDate],Date,[EndDAte))
Should be:
=DateDiff("d",[StartDate], IIf(Date<[EndDate],Date,[EndDate]))
[StartDate] and [EndDate] should both be controls on your form.
--
Dave Hargis, Microsoft Access MVP


Johnwats said:
Thanks for the reply. I couldn't get it to work, got an error #Name. Is the
current date in your example, i am afraid i can't understand the syntax.
--
Johnwats


Klatuu said:
You could use and IIf statement for this:

=DateDiff("d",[StartDate], IIf(Date<[EndDate],Date,[EndDAte))
--
Dave Hargis, Microsoft Access MVP


Johnwats said:
I am setting up a database for students on a course. I want to work out how
long students are taking on the course. In a form i have a start date, then
i have used expression builder to find number of days between the start date
& current date. That worked OK. But at some point i will be entering an end
date to the course. How do i change the expression so that it "stops" at the
end date(when entered), rather than keep on calculating to the current date?
I want the expression to somehow compare the calculated date to the end date
& use whichever is the less, but i am completely stuck.

Using Access 2000 in my first attempt at a database. Any help appreciated.
 

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