Results 1 to 4 of 4
  1. #1
    hicham6w is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    4

    Upcoming Holidays Alert


    Hello everyone,
    I have been trying to get an upcoming holidays alert on a form open. The list of holidays is in a table called "tblHolidays" with the following fields
    "HolidayMonth" as byte, "HolidayDayOfMonth" as byte. I used the following code, but it is stuck in the first record and the message box is blank:
    Code:
    Public Sub Holiday_Alert()
    
    Dim myDb As DAO.Database
    Dim rst As DAO.Recordset
    
    Dim strSQL As String
    Dim strMsg As String
    
    Dim M As Integer 'month field
    Dim D As Integer 'day field
    Dim JD As Date 'calculated holiday date
    
    Dim n As Integer
    
    Set myDb = CurrentDb()
    strSQL = "SELECT * from tblHolidays ORDER BY HolidayMonth, HolidayDayOfMonth"
    Set rst = myDb.OpenRecordset(strSQL, dbOpenSnapshot)
    
    'initial value of the msgbox
    strMsg = ""
    
    'assigning variables
    M = rst.Fields("HolidayMonth").Value
    D = rst.Fields("HolidayDayOfMonth").Value
    JD = DateSerial(Year(Date), M, D)
    
    'populate recordset
    rst.MoveLast
    rst.MoveFirst
    
    'loop to find upcoming holidays
    For n = 0 To rst.RecordCount
            rst.FindFirst (JD - Date) > 0 And (JD - Date) < 15
                        If Not rst.NoMatch Then
                            strMsg = strMsg & rst.Fields("HolidayName") & " est prévue dans " & (JD - Date) & " jours" & vbCrLf
                        End If
              'report n on status bar every 50
              If n Mod 50 = 0 Then
              DoCmd.Echo True, n
              End If
              'move next
              rst.MoveNext
              n = n + 1
    Next n
    
    'show results
    MsgBox strMsg, vbInformation, "Journées Mondiales"
    
    rst.Close
    Set rst = Nothing
    Set myDb = Nothing
    
    End Sub
    Any help would be greatly appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Why did you decide not to have Holiday dimmed as a Date datatype?

  3. #3
    hicham6w is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    4
    Quote Originally Posted by orange View Post
    Why did you decide not to have Holiday dimmed as a Date datatype?
    Thanks for you reply, it was because I wanted it to hapen every year not just this year.

  4. #4
    hicham6w is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    4
    Hello again I've finally got the code to work, Here it is :
    Code:
    Public Sub Holidays_Alert()
    
    Dim myDb As DAO.Database
    Dim rst As DAO.Recordset
    
    Dim strSQL As String
    Dim strMsg As String
    Dim strJN As String
    
    Dim M     As Integer
    Dim D     As Integer
    Dim JD    As Date
    Dim intRemaining As Integer
    
    Dim n As Integer 'counter
    Dim x As Integer
    
    Set myDb = CurrentDb()
    strSQL = "SELECT * from tblHolidays ORDER BY HolidayMonth, HolidayDayOfMonth"
    Set rst = myDb.OpenRecordset(strSQL)
    
    'initial value of the msgbox
    strMsg = ""
    
    'populate rst : unecessary ?
    'rst.MoveLast
    'rst.MoveFirst
    
    'loop to find upcoming holidays
    For n = 0 To rst.RecordCount - 1
    
    'assign vars (must be inside the loop)
    M = rst.Fields("HolidayMonth").Value           'mount field
    D = rst.Fields("HolidayDayOfMonth").Value     'day field
    strJN = rst.Fields("HolidayName").Value      'Holiday name
    JD = DateSerial(Year(Date), M, D)              'Holyday date this year
    intRemaining = JD - Date                             'remainig days
    
    'Debug.Print strJN; intRemaining
            rst.FindNext intRemaining >= 0 And intRemaining <= 15                '(in the future 15 days)
                        If Not rst.NoMatch Then
                                  strMsg = strMsg & strJN & vbTab & " dans " & intRemaining & " jours" & vbNewLine & vbCrLf
                                  x = x + 1
                        End If
    '                    'report n on status bar
    '                    If n Mod 50 = 0 Then
    '                    DoCmd.Echo True, n
    '                    End If
    rst.MoveNext
    n = n + 1
    Next n
                         
    'show results if any
    If strMsg <> "" Then
    MsgBox strMsg, vbInformation, x & " Journées Mondiales prévues dans deux semaines ..."
    End If
    
    rst.Close
    Set rst = Nothing
    Set myDb = Nothing
    
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 04-22-2015, 05:50 AM
  2. Allow for holidays
    By msmithtlh in forum Programming
    Replies: 5
    Last Post: 04-10-2014, 04:25 PM
  3. Query for upcoming expiration date
    By jones in forum Queries
    Replies: 2
    Last Post: 05-16-2012, 02:18 AM
  4. Holidays falling between dates
    By Alex Motilal in forum Queries
    Replies: 1
    Last Post: 11-15-2010, 11:59 PM
  5. calculate holidays
    By barkarlo in forum Queries
    Replies: 0
    Last Post: 12-20-2006, 06:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums