G
Gwhit
Hi,
I've been building Access databases for some time now, using code within the
forms and command buttons, etc. to perform various functions.
I'm trying to expand into modules with the following as a case in point,
seeking to convert from hard coded forms references (see the If...Then
statement) to a public function that allows ANY open form containing the
"PickDate" combo box to have the same coded rowsource as the one displayed:
Function DateCalc()
Dim strRowSource As String
strRowSource = Chr(34) & Format(DateSerial(Year(Date), Month(Date) + 1, 0),
"MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date), 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 1, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 2, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 3, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 4, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 5, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 6, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 7, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 8, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 9, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 10, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 11, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
If CurrentProject.AllForms("sbfrmRBSM").IsLoaded = True Then
Forms!sbfrmRBSM![PickDate].RowSource = strRowSource
ElseIf CurrentProject.AllForms("frmActiveProjects").IsLoaded = True Then
Forms!sbfrmActiveProjects![PickDate].RowSource = strRowSource
End If
End Function
Thank you.
I've been building Access databases for some time now, using code within the
forms and command buttons, etc. to perform various functions.
I'm trying to expand into modules with the following as a case in point,
seeking to convert from hard coded forms references (see the If...Then
statement) to a public function that allows ANY open form containing the
"PickDate" combo box to have the same coded rowsource as the one displayed:
Function DateCalc()
Dim strRowSource As String
strRowSource = Chr(34) & Format(DateSerial(Year(Date), Month(Date) + 1, 0),
"MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date), 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 1, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 2, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 3, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 4, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 5, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 6, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 7, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 8, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 9, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 10, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
strRowSource = strRowSource & Chr(34) & Format(DateSerial(Year(Date),
Month(Date) - 11, 0), "MMMM" & " " & "YYYY") & Chr(34) & ";"
If CurrentProject.AllForms("sbfrmRBSM").IsLoaded = True Then
Forms!sbfrmRBSM![PickDate].RowSource = strRowSource
ElseIf CurrentProject.AllForms("frmActiveProjects").IsLoaded = True Then
Forms!sbfrmActiveProjects![PickDate].RowSource = strRowSource
End If
End Function
Thank you.