A
Antney
Hi,
Can anyone help with this. I currently have code which lists class days and
times. Here is how it currently looks:
TuWThF, 9:00a-12:30p, 1:00p-2:30p, 9:00a-
12:30p, 1:00p-2:00p, 9:00a-12:30p, 1:00p-2:30p,
9:00a-12:30p, 1:00p-2:00p
I want it to look like this:
Tu, 9:00a-12:30p, 1:00p-2:30p
W, 9:00a- 12:30p, 1:00p-2:00p
Th, 9:00a-12:30p, 1:00p-2:30p
F, 9:00a-12:30p, 1:00p-2:30p
Here is the code I'm using:
Public Function DaysTimes(SId As Variant) As String
Dim Days As Recordset 'days
Dim QStr As String
Dim sTime As String
Dim sDay As String
sTime = ""
sDay = ""
DaysTimes = ""
If IsNull(SId) Then Exit Function
Set Days = New ADODB.Recordset
Days.ActiveConnection = CurrentProject.Connection
QStr = "SELECT SectionDays.[SectionTeacherId], SectionDays.DayofWeek,
SectionDays.StartTime, SectionDays.EndTime " & _
"FROM SectionDays " & _
"WHERE ((SectionDays.[SectionTeacherId])=" & SId & ") " & _
"ORDER BY SectionDays.DayofWeek, SectionDays.StartTime"
Days.OPEN QStr, , adOpenStatic, adLockReadOnly, adCmdText
If Days.EOF Then
Days.Close
Set Days = Nothing
Exit Function
End If
Dim D As String
Dim PrevD As String
Dim T As String
Dim PrevT As String
PrevD = ""
PrevT = ""
Days.MoveFirst
While Not Days.EOF
D = DLookup("[DayAbbrev]", "DayofWeek", "[DayNo]=" &
Format(Days.Fields("DayofWeek")))
If D <> PrevD Then sDay = sDay & D
T = Format(Days.Fields("StartTime"), "h:nna/p") & "-" &
Format(Days.Fields("EndTime"), "h:nna/p")
If T <> PrevT Then sTime = sTime & IIf(PrevT <> "", ", ", "") & T
PrevD = D
PrevT = T
Days.MoveNext
Wend
Days.Close
Set Days = Nothing
DaysTimes = sDay & ", " & sTime
End Function
If anyone has any ideas or needs me to explain in further detail, I'm all
ears!
Thank you!
Can anyone help with this. I currently have code which lists class days and
times. Here is how it currently looks:
TuWThF, 9:00a-12:30p, 1:00p-2:30p, 9:00a-
12:30p, 1:00p-2:00p, 9:00a-12:30p, 1:00p-2:30p,
9:00a-12:30p, 1:00p-2:00p
I want it to look like this:
Tu, 9:00a-12:30p, 1:00p-2:30p
W, 9:00a- 12:30p, 1:00p-2:00p
Th, 9:00a-12:30p, 1:00p-2:30p
F, 9:00a-12:30p, 1:00p-2:30p
Here is the code I'm using:
Public Function DaysTimes(SId As Variant) As String
Dim Days As Recordset 'days
Dim QStr As String
Dim sTime As String
Dim sDay As String
sTime = ""
sDay = ""
DaysTimes = ""
If IsNull(SId) Then Exit Function
Set Days = New ADODB.Recordset
Days.ActiveConnection = CurrentProject.Connection
QStr = "SELECT SectionDays.[SectionTeacherId], SectionDays.DayofWeek,
SectionDays.StartTime, SectionDays.EndTime " & _
"FROM SectionDays " & _
"WHERE ((SectionDays.[SectionTeacherId])=" & SId & ") " & _
"ORDER BY SectionDays.DayofWeek, SectionDays.StartTime"
Days.OPEN QStr, , adOpenStatic, adLockReadOnly, adCmdText
If Days.EOF Then
Days.Close
Set Days = Nothing
Exit Function
End If
Dim D As String
Dim PrevD As String
Dim T As String
Dim PrevT As String
PrevD = ""
PrevT = ""
Days.MoveFirst
While Not Days.EOF
D = DLookup("[DayAbbrev]", "DayofWeek", "[DayNo]=" &
Format(Days.Fields("DayofWeek")))
If D <> PrevD Then sDay = sDay & D
T = Format(Days.Fields("StartTime"), "h:nna/p") & "-" &
Format(Days.Fields("EndTime"), "h:nna/p")
If T <> PrevT Then sTime = sTime & IIf(PrevT <> "", ", ", "") & T
PrevD = D
PrevT = T
Days.MoveNext
Wend
Days.Close
Set Days = Nothing
DaysTimes = sDay & ", " & sTime
End Function
If anyone has any ideas or needs me to explain in further detail, I'm all
ears!
Thank you!