How do I send email reminders 2 weeks prior to the Lead Date?
Below is my SQL code from a query.
SELECT CalibrationRecord.RecordID, CalibrationRecord.CalRequirement, CalibrationRecord.CalStatus,
CalibrationRecord.CalLocation, Equipment.EquipmentType, Equipment.SerialNo, Equipment.ModelNo,
Equipment.AssetNo, CalibrationRecord.EmpName, Employees.EmailAddress, CalibrationRecord.LastCalDate,
CalibrationRecord.CalTimeInterval, CalibrationRecord.UOM,
DateAdd(IIf([CalibrationRecord]![UOM]="days","d",IIf([CalibrationRecord]![UOM]="month","m","yyyy")),
[CalTimeInterval],[LastCalDate]) AS CalUpcomingDate, CalibrationRecord.DateEmailSent,
DateAdd(IIf([Equipment]![UOM]="weeks","ww"),-[LeadInterval],[CalUpcomingDate]) AS LeadDate
FROM Equipment INNER JOIN (Employees INNER JOIN CalibrationRecord ON Employees.EmpID = CalibrationRecord.EmpName)
ON Equipment.ItemID = CalibrationRecord.EquipItemID
WHERE (((CalibrationRecord.CalStatus)="Not Started")
AND ((Employees.EmailAddress) Is Not Null)
AND ((CalibrationRecord.CalTimeInterval) Between 6 And 9)
AND ((CalibrationRecord.UOM) Like "month")
AND ((Employees.EmpName) Not Like "MFGUSER")) OR (((CalibrationRecord.UOM) Like "days"));
This is my Email reminder code. I just want to include a piece of code that will send email reminder 2 weeks prior to the Lead Date.
Function GenerateEmail(MySQL As String)
On Error GoTo Exit_Function:
Dim oOutLook As Outlook.Application
Dim oEmailAddress As MailItem
Dim MyEmpName As String
Dim MyEquip As String
Dim MyModel As String
Dim MyAsset As String
Dim MySerial As String
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(MySQL)
If rs.RecordCount > 0 Then
rs.MoveFirst
Do Until rs.EOF
If Not IsNull(rs!EmailAddress) Then
' Only Send Emails if never been sent before - or past 14 days since last one'
If (IsNull(rs!DateEmailSent)) Or DateDiff("d", rs!DateEmailSent, Date) >= 14 Then
If rs!LeadDate - 2 * 7 <= Date Then **This is what i have so far for the 2 weeks prior to Lead Date**
If oOutLook Is Nothing Then
Set oOutLook = New Outlook.Application
End If
Set oEmailAddressItem = oOutLook.CreateItem(olMailItem)
With oEmailAddressItem
'MyEmpName = DLookup("EmpName", "Employees", "[EmpID]= " & rs!EmpName)
MyEquip = rs!EquipmentType
MyModel = rs!ModelNo
MyAsset = rs!AssetNo
MySerial = rs!SerialNo
.To = "dgaskins#eeimfg.com"
.Subject = "Monthly Calibrations"
.Body = "Calibration ID: " & rs!RecordID & vbCr & _
"Location: " & rs!CalLocation & vbCr & _
"Requirement: " & rs!CalRequirement & vbCr & _
"Name: " & MyEquip & vbCr & _
"Serial No.: " & MySerial & vbCr & _
"Model No.: " & MyModel & vbCr & _
"Asset No.: " & MyAsset & vbCr & _
"Upcoming Date: " & rs!CalUpcomingDate & vbCr & vbCr & _
"This email is auto generated. Please Do Not Reply!"
'.Display
.Send
' Make sure to record that reminder was sent '
rs.Edit
rs!DateEmailSent = Date
rs!LeadDate = DateAdd("ww", -2, Now)
rs.Update
End With
' Only do this if this has been set '
Set oEmailAddressItem = Nothing
End If
End If
End If
rs.MoveNext
Loop
' Do this at end '
Set oOutLook = Nothing
Else
End If
rs.Close
Exit_Function:
Exit Function
End Function
Get rid of this If and Matching Endif
If DateDiff("d", Date, rs!LeadDate) Then **This is what i have so far for the 2 weeks prior to Lead Date**
Change this
' Only Send Emails if never been sent before - or past 14 days since last one'
If (IsNull(rs!DateEmailSent)) Or DateDiff("d", rs!DateEmailSent, Date) >= 14 Then
To This
' Only Send Emails if never been sent before
' - or past 14 days since last one
' - or with 14 days of LeadDate
If (IsNull(rs!DateEmailSent)) Or DateDiff("d", rs!DateEmailSent, Date) >= 14 Or DateDiff("d", Date, rs!LeadDate) <= 14 Then
Related
I am trying to set reminders for recurring appointments.
If objAppointment.ReminderSet = False Then
If objAppointment.IsRecurring Then
'Dim objRecurrencePattern As RecurrencePattern
'Set objRecurrencePattern = objAppointment.GetRecurrencePattern
'Set objAppointment = objRecurrencePattern.GetOccurrence(objAppointment.Start)
objAppointment.ReminderOverrideDefault = True
End If
objAppointment.ReminderSet = True
objAppointment.ReminderMinutesBeforeStart = 15 ' Enter your default time
objAppointment.Save
Debug.Print "Reminder set for '" & objAppointment.Subject & "'."
End If
I found this post in MS forum.
The reminder properties seems to be properly set in the VBA debugger but if I check the appointment in the calendar the reminder is still not set/effective.
If you are dealing with an instance of a recurring appointment or an exception (check the AppointmentItem.RecurrenceState property), set the reminder on the master appointment retrieved from the AppointmentItem.Parent property.
In case the meeting is recurring you have to edit All Occurences <->Parent meeting
See code here https://gist.github.com/tdalon/60a746cfda75ad191e426ee421324386
Sub CheckTodayReminders()
' https://www.datanumen.com/blogs/quickly-send-todays-appointments-someone-via-outlook-vba/
Dim objAppointments As Outlook.Items
Dim objTodayAppointments As Outlook.Items
Dim strFilter As String
Dim objAppointment As Outlook.AppointmentItem ' Object
Set objAppointments = Application.Session.GetDefaultFolder(olFolderCalendar).Items
objAppointments.IncludeRecurrences = True
objAppointments.Sort "[Start]", False ' Bug: use False/descending see https://social.msdn.microsoft.com/Forums/office/en-US/919e1aee-ae67-488f-9adc-2c8518854b2a/how-to-get-recurring-appointment-current-date?forum=outlookdev
'Find your today's appointments
strFilter = Format(Now, "ddddd")
'strFilter = "2019-03-07"
strFilter = "[Start] > '" & strFilter & " 00:00 AM' AND [Start] <= '" & strFilter & " 11:59 PM'"
Set objTodayAppointments = objAppointments.Restrict(strFilter)
For Each objAppointment In objTodayAppointments
Debug.Print "Check Reminder for '" & objAppointment.Subject & "'..."
If objAppointment.IsRecurring Then
Set objAppointment = objAppointment.Parent
End If
If objAppointment.ReminderSet = False Then
objAppointment.ReminderSet = True
objAppointment.ReminderMinutesBeforeStart = 15 ' Enter your default time
objAppointment.Save
Debug.Print "Reminder set for '" & objAppointment.Subject & "'."
End If
Next
' MsgBox "Meeting reminders were checked!"
End Sub
When I use restrict to set the date range on an Outlook item object, it does not pick up any appointments before whatever I have set as my "Work Hours" on Outlook. How do I make whatever the user sets as "Work Hours" not influence my macro?
Eg. My "Work Hours" in Outlook is set to 1PM to 5PM. I create 4 appointments:
1111 at 10AM Sept 4, 2017
2222 at 1PM Sept 4, 2017
3333 at 6PM Sept 4, 2017
4444 at 1PM Sept 5, 2017
My code will pick up the last 3 appointments, but not the first, if the dates I enter are 9/4/2017 and 9/5/2017.
Sub restrictDemo()
Dim olkItems As Outlook.Items, _
olkSelected As Outlook.Items, _
olkAppt As Outlook.AppointmentItem, _
dateStart As Date, _
dateEnd As Date
dateStart = InputBox("Starting date?", "", "m/d/yyyy")
dateEnd = InputBox("Ending date?", "", "m/d/yyyy")
If IsDate(dateStart) And IsDate(dateEnd) Then
Set olkItems = Session.GetDefaultFolder(olFolderCalendar).Items
olkItems.IncludeRecurrences = True
olkItems.Sort "Start"
Set olkSelected = olkItems.Restrict("[Start] >= '" & dateStart & "' AND [Start] <= '" & dateEnd & "'")
For Each olkAppt In olkSelected
counter = counter + 1
MsgBox counter
MsgBox olkAppt.Subject & " " & olkAppt.Location & olkAppt.Start
Next
Else
MsgBox "You must enter valid starting and ending dates to run this macro.", vbCritical + vbOKOnly, MACRO_NAME
End If
End Sub
Use the format expected by Restict. https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/items-restrict-method-outlook
Sub restrictDemo()
Dim Counter As Long
Dim olkItems As items
Dim olkSelected As items
Dim olkAppt As AppointmentItem
Dim dateStart
Dim dateEnd
Dim StrFilter As String
' You may need to use a different date format.
dateStart = InputBox("Starting date?", , "2017-08-22")
dateEnd = InputBox("Ending date?", , "2017-08-23")
If IsDate(dateStart) And IsDate(dateEnd) Then
Set olkItems = Session.GetDefaultFolder(olFolderCalendar).items
olkItems.IncludeRecurrences = True
olkItems.Sort "Start"
'StrFilter = "[Start] >= '" & dateStart & "' AND [Start] < '" & dateEnd & "'"
'Debug.Print StrFilter
StrFilter = "[Start] >= '" & Format(dateStart, "ddddd h:nn AMPM") & "'"
Debug.Print StrFilter
StrFilter = StrFilter & " AND [Start] < '" & Format(dateEnd, "ddddd h:nn AMPM") & "'"
Debug.Print StrFilter
Set olkSelected = olkItems.Restrict(StrFilter)
For Each olkAppt In olkSelected
Counter = Counter + 1
Debug.Print Counter & ":" & olkAppt.Subject & " " & olkAppt.location & olkAppt.start
'MsgBox Counter & ":" & olkAppt.Subject & " " & olkAppt.location & olkAppt.start
Next
Else
MsgBox "Enter valid starting and ending dates.", vbCritical + vbOKOnly, "MACRO_NAME"
End If
End Sub
The deeper question of why a day begins at the start of a work day and continues for 24 hours remains unanswered.
In Access 2016 I'm trying to open a recordset and save data from it in other variables, but I keep getting this error.
The program itself has more parts, but I only get error in this one, it just update data on its database.
This is my code:
Option Compare Database
Option Explicit
Private Sub btnValidateTimesheet_Click()
' Update timesheet to "Justificat"
Dim intIdTimesheet As Integer
If IsNull(cmbDraftTimesheets.Value) Then
MsgBox("You have to select a timesheet that is Borrador")
Exit Sub
End If
intIdTimesheet = cmbDraftTimesheets.Column(0)
DoCmd.SetWarnings False
DoCmd.RunSQL "update Timesheets set estat = ""Justificat"" where id=" & intIdTimesheet
DoCmd.SetWarnings True
End Sub
Private Sub btnValidateTimesheetLines_Click()
' We select the timesheet_lines for employee, project, activity and dates selected
' For each justification, a new "Justificat" Timesheet is generated which hang timesheet_lines
' ------------------------------- Variables -------------------------------
Dim dictTsLines As Object
Set dictTsLines = CreateObject("Scripting.Dictionary")
' Form inputs
Dim intCodTreb As Integer
Dim strCodProj As String
Dim dateInici, dateFi As Date
Dim intExercici As Integer
' Query strings
Dim strSQLFrom, strSQLWhere As String
Dim strSQLCount, strSQLJustAct, strSQLTsLines As String
' Recordsets
Dim rsCount, rsJustAct, rsTimesheets, rsTsLines As Recordset
' Aux and others...
Dim continue As Integer
Dim intIdJustificacio, intIdTs As Integer
Dim strActivitat As String
' --------------------------------------- Main ---------------------------------------------
' Taking form data
intCodTreb = cmbTreballador.Column(0)
strCodProj = cmbProjecte.Column(1)
dateInici = txtDataInici.Value
dateFi = txtDataFi.Value
' We check the dates are correct
If IsNull(dateInici) Or IsNull(dateFi) Then
MsgBox("Dates can't be null")
Exit Sub
End If
If dateFi < dateInici Then
MsgBox("Start date must be earlier or the same as final date")
Exit Sub
End If
If year(dateInici) <> year(dateFi) Then
MsgBox("Dates must be in the same year")
Exit Sub
End If
intExercici = year(dateInici)
' Make of the clause FROM and WHERE of the select query of timesheet_lines
strSQLFrom = " from (timesheet_lines tsl " & _
" left join timesheets ts on tsl.timesheet_id = ts.id) " & _
" left join justificacions j on j.id = ts.id_justificacio "
strSQLWhere = " where ts.estat = ""Borrador"" " & _
" and tsl.data >= #" & Format(dateInici, "yyyy/mm/dd") & "# " & _
" and tsl.data <= #" & Format(dateFi, "yyyy/mm/dd") & "# "
If Not IsNull(intCodTreb) Then
strSQLWhere = strSQLWhere & " and tsl.cod_treb = " & intCodTreb
End If
If Not IsNull(strCodProj) Then
strSQLWhere = strSQLWhere & " and j.cod_proj=""" & strCodProj & """ "
End If
' Alert how much timesheet_lines are going to be validated
strSQLCount = "select count(*) " & strSQLFrom & strSQLWhere
Set rsCount = CurrentDb.OpenRecordset(strSQLCount)
Continue Do = MsgBox( rsCount(0) & " registries are going to be validated" & vbNewLine & _
"Do you want to continue?", vbOKCancel)
If continue <> 1 Then
Exit Sub
End If
' We select the tuples Justificacio, Activitat of timesheet_lines selected
strSQLJustAct = "select distinct ts.id_justificacio " & strSQLFrom & strSQLWhere
Set rsJustAct = CurrentDb.OpenRecordset(strSQLJustAct)
Set rsTimesheets = CurrentDb.OpenRecordset("Timesheets")
' A new timesheet is generated for each tupla
Do While Not rsJustAct.EOF
intIdJustificacio = rsJustAct(0)
strActivitat = rsJustAct(1)
rsTimesheets.AddNew
rsTimesheets!data_generacio = Now()
rsTimesheets!estat = "Justificat"
rsTimesheets!Id_justificacio = intIdJustificacio
rsTimesheets!activitat = strActivitat
rsTimesheets!data_inici = dateInici
rsTimesheets!data_fi = dateFi
rsTimesheets!exercici = intExercici
intIdTs = rsTimesheets!Id
rsTimesheets.Update
' We save the related id of the selected timesheet in a dictionary
dictTsLines.Add intIdJustificacio & "_" & strActivitat, intIdTs
rsJustAct.MoveNext
Loop
' We select all the affected timesheet_lines and we update the related timesheet using the dictionary
strSQLTsLines = "select tsl.id, tsl.timesheet_id, ts.id_justificacio, ts.activitat " & strSQLFrom & strSQLWhere
Set rsTsLines = CurrentDb.OpenRecordset(strSQLTsLines)
With rsTsLines
Do While Not .EOF
.EDIT
intIdJustificacio = !Id_justificacio
strActivitat = !activitat
!timesheet_id = dictTsLines.Item(intIdJustificacio & "_" & strActivitat)
.Update
.MoveNext
Loop
End With
rsTimesheets.Close
Set rsCount = Nothing
Set rsJustAct = Nothing
Set rsTimesheets = Nothing
Set rsTsLines = Nothing
End Sub
Debugger: The error is coming up at the line:
strActivitat = rsJustAct(1)
I checked that the data the recordset is saving exists and it does.
Your recordset contains just one column ("select distinct ts.id_justificacio"), but you are trying to read second column strActivitat = rsJustAct(1)
Add requred column to recordset.
I need help creating some code that will send email reminders once every two weeks. I already have code that send email reminders, but it sends the emails once everyday. That can be very annoying to the users
Here is my vba code from access:
Function GenerateEmail(MySQL As String)
'On Error GoTo Exit_Function:
Dim oOutLook As Outlook.Application
Dim oEmailAddress As MailItem
Dim MyEmpName As String
Dim MyEquip As String
Dim MyModel As String
Dim MyAsset As String
Dim MySerial As String
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(MySQL)
If rs.RecordCount > 0 Then
rs.MoveFirst
Do Until rs.EOF
If IsNull(rs!EmailAddress) Then
rs.MoveNext
Else
If oOutLook Is Nothing Then
Set oOutLook = New Outlook.Application
End If
Set oEmailAddressItem = oOutLook.CreateItem(olMailItem)
With oEmailAddressItem
MyEmpName = DLookup("EmpName", "Employees", "[EmpID]= " & rs!EmpName)
MyEquip = rs!EquipmentType
MyModel = rs!ModelNo
MyAsset = rs!AssetNo
MySerial = rs!SerialNo
.To = "another#.com;another#.com;another#.com"
.Subject = "Calibration that's due between 1 to 11 months"
.Body = "Calibration ID: " & rs!RecordID & vbCr & _
"Location: " & rs!CalLocation & vbCr & _
"Requirement: " & rs!CalRequirement & vbCr & _
"Employee: " & MyEmpName & vbCr & _
"Name: " & MyEquip & vbCr & _
"Serial No.: " & MySerial & vbCr & _
"Model No.: " & MyModel & vbCr & _
"Asset No.: " & MyAsset & vbCr & _
"Due Date : " & rs!CalUpcomingDate & vbCr & vbCr & _
"This email is auto generated. Please Do Not Replay!"
'MyEmpName = DLookup("EmpName", "Employees", "[EmpID]= " & rs!EmpName)
'.To = rs!EmailAddress
'.Subject = "Task due in between 1st and 11th month reminder for " & MyEmpName
'.Body = "Task ID: " & rs!RecordID & vbCr & _
'"Task Name: " & rs!TaskName & vbCr & _
'"Employees: " & MyEmpName & vbCr & _
' "Task Due: " & rs!CalUpcomingDate & vbCr & vbCr & _
'"This email is auto generated from Task Database. Please Do Not Replay!"
.Display
'.Send
' rs.Edit
' rs!DateEmailSent = Date
' rs.Update
End With
Set oEmailAddressItem = Nothing
Set oOutLook = Nothing
rs.MoveNext
End If
Loop
Else
'do nothing
End If
rs.Close
Exit_Function:
Exit Function
End Function
It looks like you had the right idea once - and #Gustav pointed out the solution.
You first need to uncomment out the lines:
' rs.Edit
' rs!DateEmailSent = Date
' rs.Update
Then change what happens when you process each email address:
Suggested new look of your program:
rs.MoveFirst
Do Until rs.EOF
If Not IsNull(rs!EmailAddress) Then
' Only Send Emails if never been sent before - or past 14 days since last one'
If (IsNull(rs!DateEmailSent)) Or DateDiff("d", rs!DateEmailSent, Date) >= 14 Then
If oOutLook Is Nothing Then
Set oOutLook = New Outlook.Application
End If
Set oEmailAddressItem = oOutLook.CreateItem(olMailItem)
' ... rest of email processing '
' .................... '
.Display
.Send
' Make sure to record that reminder was sent '
rs.Edit
rs!DateEmailSent = Date
rs.Update
' Only do this if this has been set '
Set oEmailAddressItem = Nothing
End If
End If
rs.MoveNext
Loop
' Do this at end '
Set oOutLook = Nothing
I have an Access database that is tracking a rolling 35 week window on job data. I have it automated so once a month I run a script that generates an e-mail and attaches an Excel worksheet for the appropriate program manager so they can update their crew number count projections for the next 35 weeks. The program saves a copy of the Excel sheet so I can run a compare once the sheet has been returned.
What I would like to do is add in the missing dates from their dataset prior to building the Excel sheet that gets e-mailed. That way the table where I store the dates would have an auto-generated line item number that I could reference later when I re-import the data from the Excel file.
I suppose I could just run an update query that expands all of the job records in the database to the same end date and later purge out anything that has a zero crew count as the rolling window drops away, but is there was a better way of approaching this?
The following code will:
1. Add missing dates (but only if within 4 weeks of run date)
2. Add 35 new 'week' records to past the current date
This code requires your table design to have a Unique Key of Job_ID + WeekDate
Option Compare Database
Option Explicit
Dim dbs As DAO.Database
Dim rsJobs As DAO.recordSet
Dim rsWeek As DAO.recordSet
Function Create_New_Weeks()
Dim strSQL As String
Dim i As Integer
Dim dStartDate As Date
Dim dEndDate As Date
Dim dPriorMonday As Date
Dim dTempDate As Date
Dim strJobID As String
Const iWksToAdd = 35 ' Change as desired
On Error GoTo Error_Trap
Set dbs = CurrentDb
' Get Job_ID and Week records for all OPEN Jobs.
' Expect this to possibly be the first date, possibly a gap in dates, then
' one or more weekly dates.
strSQL = "SELECT tblProjects.Job_ID, tblProjects.DateEnded, tblJobWeeks.WorkWeek " & _
"FROM tblProjects INNER JOIN tblJobWeeks ON tblProjects.Job_ID = tblJobWeeks.Job_ID " & _
"WHERE (((tblProjects.DateEnded) Is Null)) " & _
"ORDER BY tblProjects.Job_ID, tblJobWeeks.WorkWeek;"
Set rsJobs = dbs.OpenRecordset(strSQL)
If rsJobs.EOF Then
MsgBox "No Jobs found!", vbOKOnly + vbCritical, "No Jobs"
GoTo Exit_Code
Else
rsJobs.MoveFirst
End If
' First, find prior Monday's date as a baseline
dPriorMonday = DateAdd("ww", -1, Date - (Weekday(Date, vbMonday) - 1))
' Calculate +35 weeks -- and make sure the date will be a monday.
If Weekday(Date, 1) = 2 Then
dEndDate = DateAdd("ww", iWksToAdd, Date)
Else
dEndDate = DateAdd("ww", iWksToAdd, dPriorMonday)
End If
' Open the 'Weekly' table for inserting 35 new records, plus missing dates
strSQL = "select * from tblJobWeeks order by Job_ID, WorkWeek"
Set rsWeek = dbs.OpenRecordset(strSQL)
' FYI: It doesn't make sense to add records between the 'start' date and + 35 weeks, then
' have your monthly process delete empty ones from prior months.
' This code will only add missing records going back 4 weeks.
' Your notes indicated there would be at least two records for any given Job. If that is
' not correct, this code may not work!
' Save the starting point
strJobID = rsJobs!Job_ID
dTempDate = rsJobs!WorkWeek
Do While Not rsJobs.EOF
Debug.Print "Job: " & rsJobs!Job_ID & vbTab & "First Date: " & rsJobs!WorkWeek & vbTab & "W/E: " & rsJobs!WorkWeek
If strJobID <> rsJobs!Job_ID Then ' We have changed to a NEW Job_ID
' Fill the +35 weeks
' Only add prior 4 wks , then +35
If dTempDate < dEndDate Then dTempDate = DateAdd("ww", -3, dPriorMonday) ' Get date from 3 or 4 weeks back.
Do
If dTempDate < dEndDate Then
' Don't add dates over 4 weeks old - Remove this if necessary
If dTempDate >= DateAdd("ww", -4, Date) Then
Debug.Print "Insert ID: " & strJobID & vbTab & dTempDate
Add_Week strJobID, dTempDate
Else
Debug.Print "Skip - Older than 4 weeks: " & vbTab & dTempDate
End If
dTempDate = DateAdd("ww", 1, dTempDate)
Else
Exit Do
End If
Loop
strJobID = rsJobs!Job_ID
dTempDate = DateAdd("ww", 1, rsJobs!WorkWeek) ' Should be the FIRST date for this Job
Else
If rsJobs!WorkWeek = dTempDate Then
dTempDate = DateAdd("ww", 1, dTempDate)
Else
' Don't add dates over 4 weeks old - Remove this if necessary
If dTempDate > DateAdd("ww", -4, Date) Then
Debug.Print "Insert ID: " & strJobID & vbTab & dTempDate
Add_Week strJobID, dTempDate
Else
Debug.Print "Skip - Older than 4 weeks: " & vbTab & dTempDate
End If
dTempDate = DateAdd("ww", 1, dTempDate)
End If
End If
rsJobs.MoveNext
Loop
'Check if last ID has +35 dates
If dTempDate < dEndDate Then
Do Until dEndDate = dTempDate
' Don't add dates over 4 weeks old - Remove this if necessary
If dTempDate > DateAdd("ww", -4, Date) Then
Debug.Print "Insert ID: " & strJobID & vbTab & dTempDate
Add_Week strJobID, dTempDate
Else
Debug.Print "Skip - Older than 4 weeks: " & vbTab & dTempDate
End If
dTempDate = DateAdd("ww", 1, dTempDate)
Loop
End If
Exit_Code:
If Not rsJobs Is Nothing Then
rsJobs.Close
Set rsJobs = Nothing
End If
If Not rsWeek Is Nothing Then
rsWeek.Close
Set rsWeek = Nothing
End If
dbs.Close
Set dbs = Nothing
Exit Function
Error_Trap:
Debug.Print Err.Number & vbTab & Err.Description & vbCrLf & "In: Create_New_Weeks"
' If duplicate record, ignore
If Err.Number = 3022 Then
Resume Next
End If
MsgBox Err.Number & vbTab & Err.Description & vbCrLf & "In: Create_New_Weeks"
Create_New_Weeks = "Error: " & Err.Number & vbTab & Err.Description & vbCrLf & "In: Create_New_Weeks"
Resume Exit_Code
Resume
End Function
Function Add_Week(strID As String, dDate As Date)
With rsWeek
.AddNew
!Job_ID = strID
!WorkWeek = dDate
!Crew_Num = 0
.Update
End With
End Function