Access.2007.VBA.Bibl..

(John Hannent) #1
Private Sub FillDateControls()

On Error GoTo ErrorHandler

Dim strFormattedDate As String

Fill week ending and weekday controls with text:


Me![txtWeekEnding].Value = CurrentWeekEnding
strFormattedDate = Format(DateAdd(“d”, -6, _
CDate(Me![WeekEnding])), “dddd, mmmm d, yyyy”)
Me![lblMondayDate].Caption = strFormattedDate
strFormattedDate = Format(DateAdd(“d”, -5, _
CDate(Me![WeekEnding])), “dddd, mmmm d, yyyy”)
Me![lblTuesdayDate].Caption = strFormattedDate
strFormattedDate = Format(DateAdd(“d”, -4, _
CDate(Me![WeekEnding])), “dddd, mmmm d, yyyy”)
Me![lblWednesdayDate].Caption = strFormattedDate
strFormattedDate = Format(DateAdd(“d”, -3, _
CDate(Me![WeekEnding])), “dddd, mmmm d, yyyy”)
Me![lblThursdayDate].Caption = strFormattedDate
strFormattedDate = Format(DateAdd(“d”, -2, _
CDate(Me![WeekEnding])), “dddd, mmmm d, yyyy”)
Me![lblFridayDate].Caption = strFormattedDate
strFormattedDate = Format(DateAdd(“d”, -1, _
CDate(Me![WeekEnding])), “dddd, mmmm d, yyyy”)
Me![lblSaturdayDate].Caption = strFormattedDate
strFormattedDate = Format((Me![WeekEnding]), _
“dddd, mmmm d, yyyy”)
Me![lblSundayDate].Caption = strFormattedDate

ErrorHandlerExit:
Exit Sub

ErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit

End Sub

Additionally, the code runs a make-table query that creates a table for use in the query that is the
row source of cboClientProject (see Figure 7.12); initially, the combo box’s row source is blank,
because otherwise the query could not be run. The row source query is a FindUnmatched query
created with the Query Wizard that excludes client/project combinations for worksheets that have
already been filled out for the selected employee, so you can’t accidentally select the same one twice.


Working with Excel Worksheets 7

Free download pdf