Hiya, I thought I was sorted, even did a trial run at the weekend but now coming to run them for real and getting the attached errors..
This is the code on the form (not sure I uploaded it properly)...
Any ideas please?
Option Compare Database
Option Explicit
Dim OutlookApp As Outlook.Application
Private Sub cmdSave_Click()
If IsDate(Me.txtStart) And IsDate(Me.txtEnd) And Me.txtEnd >= Me.txtStart Then
LoopPaySlips Me.txtStart, Me.txtEnd
MsgBox "Complete. Check export folder"
DoCmd.Close acForm, Me.Name
Else
MsgBox "Check valid dates"
End If
End Sub
Private Sub Form_Load()
Me.txtStart = Date - Weekday(Date, vbMonday) + 1
Me.txtEnd = Date - Weekday(Date, vbMonday) + 6
End Sub
Public Sub LoopPaySlips(startDate As Date, enddate As Date)
Dim empID As String
Dim EmpName As String
Dim rs As DAO.Recordset
Dim strSql As String
strSql = "Select Distinct [Employee ID] from qryPaySlips where [Date] between #" & Format(startDate, "mm/dd/yyyy") & "# AND #" & Format(enddate, "mm/dd/yyyy") & "#"
Debug.Print strSql
Set rs = CurrentDb.OpenRecordset(strSql)
Set OutlookApp = New Outlook.Application
Do While Not rs.EOF
empID = rs![Employee ID]
CreatePaySlip startDate, enddate, empID
rs.MoveNext
Loop
Set OutlookApp = Nothing
End Sub