Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What day is it? 2

Status
Not open for further replies.

RemyS

Technical User
Jul 3, 2001
100
GB
Hi everyone,

This is just something that was puzzling me as to why I couldn't find a simple function, in Access 97, to state the day in a text box [Daybox] on a form.

This line, inserted before 'Me.Requery' in a Private Sub does the trick, if a little long windedly;

If WeekDay(DATECHOOSER, vbMonday) = 1 Then Daybox.Value = "Monday" Else If WeekDay(DATECHOOSER, vbMonday) = 2 Then Daybox.Value = "Tuesday" Else If WeekDay(DATECHOOSER, vbMonday) = 3 Then Daybox.Value = "Wednesday" Else If WeekDay(DATECHOOSER, vbMonday) = 4 Then Daybox.Value = "Thursday" Else If WeekDay(DATECHOOSER, vbMonday) = 5 Then Daybox.Value = "Friday"
' Continue the sequence if Weekend days are required
note: [DATECHOOSER] is another textbox which shows the source date.


If anyone knows of a simpler way of doing this, please post it as a Helpful Tip. I'm sure others would appreciate this trivial piece of functionality.

:cool:
Cheers,
Rémy
 


Hi RemyS

Just need to create an array.

x = Weekday(DATECHOOSER, vbMonday)

myDay = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
MsgBox myDay(x - 1)

Stew

"Make good use of bad rubbish."
 
Remy:

I think that's about the only way to get the literal value for the day of the week.

I would suggest a Select Case alternative to an If/Then/Else statement. It's a bit more efficient since it will cease processing as soon as a match is found.
Larry De Laruelle
larry1de@yahoo.com

 
The following is one step less, but not less complicated.


choose(Weekday(XX, vbMonday), "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")


Of Course, "XX" is just some recognizable date value - as shown below:


For XX = Now to (Now + 7): ? choose(Weekday(XX, vbMonday), "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"): Next XX
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Mon
MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Use this to format for Abbreviated weekday names:
Format(DateChooser,"ddd")

Use this to format for Full weekday names:
Format(DateChooser,"dddd")

DateChooser must be declared a Date type.
 
O.K. I'll promise to NOT do anymore on this one!


Code:
For XX = Now to (Now + 7): ? WeekdayName(Weekday(XX)): Next XX
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Monday

Of course it only works with ver 2K



MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
This is precisely the reason why I really enjoy VB!

So many paths and alternatives to choose from.

I opted to use Johnlowells' method for it's blindingly obvious simplicity.

Thanks everyone for the suggestions.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top