Access.2007.VBA.Bibl..

(John Hannent) #1

In the form footer there are three command buttons: the first (“Clear This Timesheet”) clears the
timesheet so you can start over; the second (“Save This Timesheet”) saves the current timesheet
and starts a new record for entering another timesheet; and the third (“Send Timesheets to Excel”)
opens a dialog form listing the timesheets that have been completed for the current week, for
review. The three command button event procedures are listed as follows:


Private Sub cmdClearTimesheet_Click()

On Error Resume Next

Delete record in temp table:


DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Me![cboClientProject].RowSource = “”

End Sub

Private Sub cmdSendToExcel_Click()

On Error GoTo ErrorHandler

DoCmd.OpenForm FormName:=”fdlgTimesheets”
DoCmd.Close acForm, Me.Name

ErrorHandlerExit:
Exit Sub

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

End Sub

The frmWeeklyTimesheet form is bound to a temp table, tblWeeklyTimesheetTemp, to ensure that
data won’t be saved to the regular table (tblWeeklyTimesheet) until the user chooses to save it, and
required fields have been filled in:


Private Sub cmdSaveTimesheet_Click()

On Error GoTo ErrorHandler

Check that required fields have values, and exit if not:


strTitle = “Value required”

If Nz(Me![cboEmployeeID].Value) = “” Then
strPrompt = “Please select an employee”

Working with Excel Worksheets 7

Free download pdf