Date Range of Start and End Dates

A

Ann

I am using Access 2002. I have three fields: txtQuarter which I want to
hold 1st, 2nd, 3rd or 4th. I have two date fields dtmStartDate and
dtmEndDate. Both are long dates so when I type 01/08/2010 I get Friday,
January 8, 2010. What I want to do is have the txtQuarter field filled in
with the appropriate quarter depending on the date range for dtmStartDate and
dtmEndDate. I'm a beginner to VB and not having much luck. Also, which is
the best Event to put this on? I was trying the AfterUpdate Event of
txtEndDate. Thanks in advance for the help.
 
B

Brendan Reynolds

Ann said:
I am using Access 2002. I have three fields: txtQuarter which I want to
hold 1st, 2nd, 3rd or 4th. I have two date fields dtmStartDate and
dtmEndDate. Both are long dates so when I type 01/08/2010 I get Friday,
January 8, 2010. What I want to do is have the txtQuarter field filled in
with the appropriate quarter depending on the date range for dtmStartDate
and
dtmEndDate. I'm a beginner to VB and not having much luck. Also, which
is
the best Event to put this on? I was trying the AfterUpdate Event of
txtEndDate. Thanks in advance for the help.


You could use an expression in the Control Source property of the Quarter
text box ...

=DatePart("q",[txtStartDate])

Or you could do it with some code in the After Update event procedure of the
Start Date text box ...

Private Sub txtStartDate_AfterUpdate()

Me.txtQuarter = DatePart("q", Me.txtStartDate)

End Sub
 
A

Ann

Brendan,

Thanks so much that did exactly what I wanted. I was making it harder then
it was. I didn't know there was a datepart for quarters. I've only used the
year so far. Thanks again.

Brendan Reynolds said:
Ann said:
I am using Access 2002. I have three fields: txtQuarter which I want to
hold 1st, 2nd, 3rd or 4th. I have two date fields dtmStartDate and
dtmEndDate. Both are long dates so when I type 01/08/2010 I get Friday,
January 8, 2010. What I want to do is have the txtQuarter field filled in
with the appropriate quarter depending on the date range for dtmStartDate
and
dtmEndDate. I'm a beginner to VB and not having much luck. Also, which
is
the best Event to put this on? I was trying the AfterUpdate Event of
txtEndDate. Thanks in advance for the help.


You could use an expression in the Control Source property of the Quarter
text box ...

=DatePart("q",[txtStartDate])

Or you could do it with some code in the After Update event procedure of the
Start Date text box ...

Private Sub txtStartDate_AfterUpdate()

Me.txtQuarter = DatePart("q", Me.txtStartDate)

End Sub
 

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