Thank you for responding pr2-eugin.
What I am trying to do is make a calendar form. It has text boxes named text0 to text 41 and list boxes name list0 to list41. The text boxes hold the days of the month and the list boxes will hold the information of the things scheduled for that day. I want my list boxes to have two columns. I have a table named tblCalendarSettings which holds the information of what table to holds the information of what table to look at to get the information for the calendar and what fields to look at which I want it to look at the table tblSchedule and the fields ID, Done, and EventDescription. I have data in tblCalendarSettings and in tblSchedule.
Here is the code I have to assign values:
Functions AssignValues()
Dim db As Database
Dim rs As Recordset
Dim STRSQL As String
Dim strDone As String
Dim strField As String
Dim strSource As String
Dim strDateField As String
Dim strForm As String
Dim strFieldID As String
Dim strFormDateName As String
Dim fDateFilter As Boolean
Dim strNewForm As String
Dim strNewDateName As String
Dim fNewOption As Boolean
If IsNull(OpenArgs) Then
intSetting = Me.textsettingid
Else
intSetting = OpenArgs
Me.textsetting = OpenArgs
Me.testsettingis = intSetting
EndIf
STRSQL = "SELECT " FROM tbleCaledarSettings where ([SettingID] = " & intSetting & ")"
Set db = Current Db()
Set rs = db.OpenRecordset(STRSQL)
With rs
If Not (.BOF and .EOF) Then
strField = !FieldName
strSource = !SourceName
strDateField = !DateFieldName
strForm = !FormName
strDone = !FieldOther
strFieldID = !FieldIDName
strFormDateName = !FormDateName
fDateFilter = !UseDateFilter
strNewForm = !NewFormName
strNewDateName = !NewFormDateName
fNewOption = !IncludeNewOption
Else
MsgBox "Calendar setting ID " & intSetting & " needs to set up before opening the calendar.",,"Setting ID " & intSetting & " Doesn't Exist"
GoTo Calendar_Close
End If
End With
Set rs = Nothing: Set db = Nothing
Call SetLists
Call SetFirstPos
intTodayPos = int(Format(Date, "dd")) + int((7- Format(fcalendarday(Format(date,"mm"), Format(Date, "yyyy"), "dd")))
Call calendarrefreshing
Exit_Sub
Exit Function
Calendar_Close
DoCmd.Close
Exit Function
End Funtion
Here is the code I have for filling the calendar and the code I get an error on for the STRSQL Line:
Private Sub fillcalendar()
ReDim griddate(0 to 41)
Dim i As Interger
Dim STRSQL As String
Dim db As Database
Dim rs As Recordset
Dim fEmpty As Boolean
Dim strUnionSQL As String
Dim strRowSource As String
Dim strDone As String
STRSQL = "SELECT " & strSource & "." & strField & ", " & strSource & "." & strDone & ", " & strSouce & "." & strField & " FR
OM " & strSource
Set db = CurrentDb()
Set rs = db.OpenRecordset(STRSQL)
If fNewOption Then
strUnionSQL = " UNION SELECT " & Chr(34) & Chr(34) & " AS " & strFieldID & ", " & Chr(34) & "No" & Chr(34) & " AS " & strDone & ", " & Chr(34) & "New" & Chr(34) & " AS " & strField & " FR
OM " & strSource
Else
strUnionSQL = ""
End If
griddate(0) = fcalendarday([Combomonth],[Comboyear],1,1)
Me.Text0.Value = Int(Formate(griddate(0),"dd"))
Me.List0.ColumnCount = 3
Me.List0.ColumnWidths = "0;0.5;1"
fEmpty = (rs.BOF and rs.EOF)
If fEmpty Then
strRowSource = Mid(Nz(strUnionSQL, "1234567"), 8)
Else
strRowSouce = "SELECT " & strSource & "." & strFieldID & ", " & strSource & "." & strDone & ", " & strSource "." & strField & " FROM " & STRsOURCE & _
" WHERE(((" & strSource & "." strDateField & ")= #" & Format(griddate(0), "mm/dd/yyyy") & "#))"& _
strUnionSQL
End If
Me.List0.RowSource = strRowSource
For i = 1 to 41
griddate(i) = DateAdd("d",i,griddate(0))
Controls("text" & i).Value = Int(Format(gridddate(i),"dd"))
If fEmpty Then
strRowSource = Mid(Nz(strUnionSQL, "1234567 "), 8)
Else
strRowSouce = "SELECT " & strSource & "." & strFieldID & ", " & strSource & "." & strDone & ", " & strSource "." & strField & " FROM " & STRsOURCE & _
" WHERE(((" & strSource & "." strDateField & ")= #" & Format(griddate(i), "mm/dd/yyyy") & "#))"& _
strUnionSQL
End If
Controls("list" & i).RowSource = strRowSource
Next i
End Sub
The following code will work for 1 column:
Private Sub fillcalendar()
ReDim griddate(0 to 41)
Dim i As Interger
Dim STRSQL As String
Dim db As Database
Dim rs As Recordset
Dim fEmpty As Boolean
Dim strUnionSQL As String
Dim strRowSource As String
STRSQL = "SELECT " & strSource & "." & strField & ", " & strSouce & "." & strField & " FR
OM " & strSource
Set db = CurrentDb()
Set rs = db.OpenRecordset(STRSQL)
If fNewOption Then
strUnionSQL = " UNION SELECT " & Chr(34) & Chr(34) & " AS " & strFieldID & ", " & Chr(34) & "New" & Chr(34) & " AS " & strField & " FR
OM " & strSource
Else
strUnionSQL = ""
End If
griddate(0) = fcalendarday([Combomonth],[Comboyear],1,1)
Me.Text0.Value = Int(Formate(griddate(0),"dd"))
Me.List0.ColumnCount = 2
Me.List0.ColumnWidths = "0;1"
fEmpty = (rs.BOF and rs.EOF)
If fEmpty Then
strRowSource = Mid(Nz(strUnionSQL, "1234567"), 8)
Else
strRowSouce = "SELECT " & strSource & "." & strFieldID & ", " & strSource "." & strField & " FROM " & STRsOURCE & _
" WHERE(((" & strSource & "." strDateField & ")= #" & Format(griddate(0), "mm/dd/yyyy") & "#))"& _
strUnionSQL
End If
Me.List0.RowSource = strRowSource
For i = 1 to 41
griddate(i) = DateAdd("d",i,griddate(0))
Controls("text" & i).Value = Int(Format(gridddate(i),"dd"))
If fEmpty Then
strRowSource = Mid(Nz(strUnionSQL, "1234567 "), 8)
Else
strRowSouce = "SELECT " & strSource & "." & strFieldID & ", " & strSource "." & strField & " FROM " & STRsOURCE & _
" WHERE(((" & strSource & "." strDateField & ")= #" & Format(griddate(i), "mm/dd/yyyy") & "#))"& _
strUnionSQL
End If
Controls("list" & i).RowSource = strRowSource
Next i
End Sub
Thank you in advance to any help you may be able to give me.