Access date in 1 field and day in another

G

George

I have a Form that allows me to enter the date in one field and the day of
the week (as a 3 letter day) into another field.

I want to have the day computed once it has been entered into the date
field, so I don't have to enter the day in the day field.

How can this be done and what area does the code get placed?
Thanks for any and all help.
 
D

Dale Fye

George,

You can use the AfterUpdate event of the date control, something like:

Private sub txtDate_AfterUpdate

if isdate(me.txtDate) then
me.txt_DayOfWeek = format(me.txtDate, "ddd")
else
me.txt_DayOfWeek = NULL
end if

End Sub

If txtDate is a bound control, then you will also need to put this code in
the Form_Current event, or call this subroutine from that event.

Private Sub Form_Current

Call txtDate_AfterUpdate

End Sub

HTH
Dale

It t
 
J

John Spencer

Don't bother to STORE the value in a field. You can calculate it whenever you
need it using
Format([YourDateField],"ddd")

The only reason to actually store the day name would be if you had a very
large dataset and needed to search on the day of the week across tens of
thousands of records AND the performance was unacceptable. Normally not an issue.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
J

John W. Vinson

I have a Form that allows me to enter the date in one field and the day of
the week (as a 3 letter day) into another field.

Why?

So the user can type #1/18/2010# into the textbox and have "Wed" in the other?
I want to have the day computed once it has been entered into the date
field, so I don't have to enter the day in the day field.

The Control Source property of the second textbox could be

=Format([firsttextbox], "ddd")

to display the date. The second textbox would not be editable and would not be
stored in the table (but of course you wouldn't want either).
 

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