Hi Folks,
I have some code which I obtained from this forum, which I have included in my database as a module and the code is as follows:
'================
BEGIN CODE
'================
Public Function LastWorkDay() As Date
'-- Return the last working day of the current month
Dim Searching As Boolean
Searching = True
LastWorkDay = DateSerial(Year(Date), Month(Date) + 1, 0) '-- Start at the last day of the month
Do While Searching
If Weekday(LastWorkDay, vbMonday) > 5 Then
'-- Weekend day, back up a day
LastWorkDay = LastWorkDay - 1
Else
'-- If you have a Holiday Table then enable the next IF...Else
' If Weekday(LastWorkday, vbMonday) > 5 Or _
Not IsNull(DLookup("[HoliDate]", "tblHolidays", _
"[HoliDate] = " & Format(LastWorkday, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
'-- The above Format of LastWorkday works with US or UK dates!
' LastWorkday = LastWorkday - 1
' Else
'-- The search is over
Searching = False
End If
Loop
End Function
===============
END CODE
===============
My module is called modLastWorkDay. I have written the following code in my progress form:
==============
BEGIN CODE
==============
Dim LastWorkDayOfMonth 'Declare LastWorkDayOfMonth variable
Dim dtmDate 'Declare dtmDate variable
Dim CurrentDay 'Declare CurrentDay variable
CurrentDay = Format(Date, "dd/mm/yy") 'Assign the current date to the CurrentDay variable
Call LastWorkDay 'Call the LastWorkDay Function
LastWorkDayOfMonth = LastWorkDay 'Assign the value of LastWorkDay to the LastWorkDayOfMonth variable
'If the current date ie equal to the LastWork Day Of The Month then
If LastWorkDayOfMonth = CurrentDay Then
'Print the Monthly Letter Type Chart
DoCmd.OpenReport "rptChartMonthlyLetterCount", acNormal, "", ""
DoCmd.OpenReport "rptStatsMonth", acNormal, "", ""
'Append Monthly data to tblCommercial table
DoCmd.OpenQuery "qryAppCommercial", acNormal, acEdit
'Export the contents of the tblCommercial table to the Commerical folder on the Question on 'Leint03' drive with the current date
DoCmd.TransferText acExportFixed, "CommercialExportSpec", "tblCommercial", "E:\Commercial\Commercial" & "_" & Format(Date, "ddmmyy") & ".txt", False, ""
'Delete the data from the tblCommercial table
DoCmd.OpenQuery "qryDelCommercial", acNormal, acEdit
End If
==============
END CODE
==============
The problem is, that whenever it is the last working day of the month the code doesn't print my reports or output my text file! So clearly there is something wrong with the way my code is written. Any help would be most appreciated.
John
I have some code which I obtained from this forum, which I have included in my database as a module and the code is as follows:
'================
BEGIN CODE
'================
Public Function LastWorkDay() As Date
'-- Return the last working day of the current month
Dim Searching As Boolean
Searching = True
LastWorkDay = DateSerial(Year(Date), Month(Date) + 1, 0) '-- Start at the last day of the month
Do While Searching
If Weekday(LastWorkDay, vbMonday) > 5 Then
'-- Weekend day, back up a day
LastWorkDay = LastWorkDay - 1
Else
'-- If you have a Holiday Table then enable the next IF...Else
' If Weekday(LastWorkday, vbMonday) > 5 Or _
Not IsNull(DLookup("[HoliDate]", "tblHolidays", _
"[HoliDate] = " & Format(LastWorkday, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
'-- The above Format of LastWorkday works with US or UK dates!
' LastWorkday = LastWorkday - 1
' Else
'-- The search is over
Searching = False
End If
Loop
End Function
===============
END CODE
===============
My module is called modLastWorkDay. I have written the following code in my progress form:
==============
BEGIN CODE
==============
Dim LastWorkDayOfMonth 'Declare LastWorkDayOfMonth variable
Dim dtmDate 'Declare dtmDate variable
Dim CurrentDay 'Declare CurrentDay variable
CurrentDay = Format(Date, "dd/mm/yy") 'Assign the current date to the CurrentDay variable
Call LastWorkDay 'Call the LastWorkDay Function
LastWorkDayOfMonth = LastWorkDay 'Assign the value of LastWorkDay to the LastWorkDayOfMonth variable
'If the current date ie equal to the LastWork Day Of The Month then
If LastWorkDayOfMonth = CurrentDay Then
'Print the Monthly Letter Type Chart
DoCmd.OpenReport "rptChartMonthlyLetterCount", acNormal, "", ""
DoCmd.OpenReport "rptStatsMonth", acNormal, "", ""
'Append Monthly data to tblCommercial table
DoCmd.OpenQuery "qryAppCommercial", acNormal, acEdit
'Export the contents of the tblCommercial table to the Commerical folder on the Question on 'Leint03' drive with the current date
DoCmd.TransferText acExportFixed, "CommercialExportSpec", "tblCommercial", "E:\Commercial\Commercial" & "_" & Format(Date, "ddmmyy") & ".txt", False, ""
'Delete the data from the tblCommercial table
DoCmd.OpenQuery "qryDelCommercial", acNormal, acEdit
End If
==============
END CODE
==============
The problem is, that whenever it is the last working day of the month the code doesn't print my reports or output my text file! So clearly there is something wrong with the way my code is written. Any help would be most appreciated.
John