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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through even numbers

Status
Not open for further replies.

access101

Programmer
Sep 4, 2010
68
0
0
US
Can someone help me loop this?


If Weekday(4) Then
If Time() < TimeValue("18:30") Then
Me.cmbShifts = Me.cmbShifts.ItemData(0)
End If
End If

If Weekday(5) Then
If Time() < TimeValue("18:30") Then
Me.cmbShifts = Me.cmbShifts.ItemData(2)
End If
End If

If Weekday(6) Then
If Time() < TimeValue("18:30") Then
Me.cmbShifts = Me.cmbShifts.ItemData(4)
End If
End If

If Weekday(7) Then
If Time() < TimeValue("18:30") Then
Me.cmbShifts = Me.cmbShifts.ItemData(6)
End If
End If
 
You wanted something like this ?
Code:
For i = 4 To 7
  If Weekday(i) Then
    If Time() < TimeValue("18:30") Then
      Me.cmbShifts = Me.cmbShifts.ItemData((i - 4) * 2)
    End If
  End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
yes but for some reason when i change the date the combobox shows the same value?
 
I doubt you would ever use code like:
Code:
If Weekday(4) Then

The Weekday() function typically expects a date value as an argument. The number four is actually 1/3/1900 so your expression is:
Code:
If Weekday(#1/3/1900#) Then

Do you actually want to test a date to see if it is a Wednesday?

Duane
Hook'D on Access
MS Access MVP
 
i want to check the weekday and off of that auto select an item in my combobox. Basically if its Wednesday and before 6:30pm then select Wed AM.
In my combo list i have:

wed am
wed pm
Thu am
Thu pm
Fri am
Fri pm
Sat am
Sat pm
Sun am
Sun pm
Mon am
Mon pm
Tue am
Tue pm
 
access101 said:
i want to check the weekday
Check the weekday of what, the current date or some date from a field in a table or some date a user enters?

Why don't you start with an explanation of what you are attempting to do and why?

Duane
Hook'D on Access
MS Access MVP
 
the current date. each selection runs a report for that shift
 
If Time() < TimeValue("18:30") Then
Me.cmbShifts = Me.cmbShifts.ItemData((weekday(date()) - 4) * 2)
End If
 
Does not sound like much of an explanation.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
To get the weekday of the current date then use Weekday(Date()).

I think you are working too hard with this:
Code:
If Time() < TimeValue("18:30") Then

which could be:
Code:
If Time() < #18:30# Then

Again could you back up a bit and tell us what you are attempting to do rather than providing code that is clearly wrong?

Duane
Hook'D on Access
MS Access MVP
 
Not quite sure that we need an If at all ... for example:

Code:
[blue]Me.cmbShifts.Value = Format(Date, "ddd ") & Format(DateAdd("h", 6.5, Date), "am/pm")[/blue]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top