C
Chris Ryner
Has anyone used Michael Blakes Access97 CalendarDB? I have Been modifying
it to better suit my specific needs and I have run into a snag with some
coding on the SQL for populating the list boxes.
The list box for a specific day will contain the word new (added via Union)
always at the top of the list. then all of the appts for that day follow.
The appts don't appear to be in order. How can I make this happen so that
the earliest appt for a day is the first in that days list box following Add
New ???
Any one have a solution please feel free to reply as I have exhausted my
abilities. I feel that the strSQL or strUnionSQL need to have an orderby
something.
here is the code that populates the list boxes.
Private Sub FillDates()
'*******************************************
'Author: Michael Blake
'Contact Via: www.weAscend.com
'Date: October 12, 2000, 04:09:01 PM
'Copyright ©2000 Michael Blake
'Please keep comments intact when using code
'*******************************************
ReDim aGridDate(1 To 42)
Dim i As Integer
Dim strRowSource As String
Dim strSQL As String
Dim db As Database
Dim rs As Recordset
Dim fEmpty As Boolean
Dim strUnionSQL As String
strSQL = "SELECT " & strSource & "." & strFieldID & ", " & _
strSource & "." & strField & " FROM " & strSource
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL)
If fNewOption Then
strUnionSQL = " UNION SELECT " & Chr(34) & Chr(34) & " AS " & strFieldID
& ", " & Chr(34) & _
"Add New" & Chr(34) & " AS " & strField & " FROM " &
strSource
Else
strUnionSQL = ""
End If
aGridDate(1) = fCalendarDay([cboMonth], [cboYear], 1, 1)
Me.txt1.Value = Int(Format(aGridDate(1), "dd"))
Me.lst1.ColumnCount = 2
Me.lst1.ColumnWidths = "0;1"
fEmpty = (rs.BOF And rs.EOF)
If fEmpty Then
strRowSource = Mid(Nz(strUnionSQL, "1234567 "), 8)
Else
strRowSource = "SELECT " & strSource & "." & strFieldID & ", " & _
strSource & "." & strField & " FROM " & strSource & _
" WHERE (((" & strSource & "." & strDateField & ")= #" &
Format(aGridDate(1), "mm/dd/yyyy") & "#))" & _
strUnionSQL
End If
Me.lst1.RowSource = strRowSource
For i = 2 To 42
aGridDate(i) = DateAdd("d", i - 1, aGridDate(1))
Controls("txt" & i).Value = Int(Format(aGridDate(i), "dd"))
If fEmpty Then
strRowSource = Mid(Nz(strUnionSQL, "1234567 "), 8)
Else
strRowSource = "SELECT " & strSource & "." & strFieldID & ", " & _
strSource & "." & strField & " FROM " & strSource & _
" WHERE (((" & strSource & "." & strDateField & ")= #" &
Format(aGridDate(i), "mm/dd/yyyy") & "#))" & _
strUnionSQL
End If
Controls("lst" & i).RowSource = strRowSource
Next i
Set db = Nothing: Set rs = Nothing
End Sub
it to better suit my specific needs and I have run into a snag with some
coding on the SQL for populating the list boxes.
The list box for a specific day will contain the word new (added via Union)
always at the top of the list. then all of the appts for that day follow.
The appts don't appear to be in order. How can I make this happen so that
the earliest appt for a day is the first in that days list box following Add
New ???
Any one have a solution please feel free to reply as I have exhausted my
abilities. I feel that the strSQL or strUnionSQL need to have an orderby
something.
here is the code that populates the list boxes.
Private Sub FillDates()
'*******************************************
'Author: Michael Blake
'Contact Via: www.weAscend.com
'Date: October 12, 2000, 04:09:01 PM
'Copyright ©2000 Michael Blake
'Please keep comments intact when using code
'*******************************************
ReDim aGridDate(1 To 42)
Dim i As Integer
Dim strRowSource As String
Dim strSQL As String
Dim db As Database
Dim rs As Recordset
Dim fEmpty As Boolean
Dim strUnionSQL As String
strSQL = "SELECT " & strSource & "." & strFieldID & ", " & _
strSource & "." & strField & " FROM " & strSource
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL)
If fNewOption Then
strUnionSQL = " UNION SELECT " & Chr(34) & Chr(34) & " AS " & strFieldID
& ", " & Chr(34) & _
"Add New" & Chr(34) & " AS " & strField & " FROM " &
strSource
Else
strUnionSQL = ""
End If
aGridDate(1) = fCalendarDay([cboMonth], [cboYear], 1, 1)
Me.txt1.Value = Int(Format(aGridDate(1), "dd"))
Me.lst1.ColumnCount = 2
Me.lst1.ColumnWidths = "0;1"
fEmpty = (rs.BOF And rs.EOF)
If fEmpty Then
strRowSource = Mid(Nz(strUnionSQL, "1234567 "), 8)
Else
strRowSource = "SELECT " & strSource & "." & strFieldID & ", " & _
strSource & "." & strField & " FROM " & strSource & _
" WHERE (((" & strSource & "." & strDateField & ")= #" &
Format(aGridDate(1), "mm/dd/yyyy") & "#))" & _
strUnionSQL
End If
Me.lst1.RowSource = strRowSource
For i = 2 To 42
aGridDate(i) = DateAdd("d", i - 1, aGridDate(1))
Controls("txt" & i).Value = Int(Format(aGridDate(i), "dd"))
If fEmpty Then
strRowSource = Mid(Nz(strUnionSQL, "1234567 "), 8)
Else
strRowSource = "SELECT " & strSource & "." & strFieldID & ", " & _
strSource & "." & strField & " FROM " & strSource & _
" WHERE (((" & strSource & "." & strDateField & ")= #" &
Format(aGridDate(i), "mm/dd/yyyy") & "#))" & _
strUnionSQL
End If
Controls("lst" & i).RowSource = strRowSource
Next i
Set db = Nothing: Set rs = Nothing
End Sub