Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 26th, 2004, 09:12 AM
Registered User
 
Join Date: Jun 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Message Box Reminder

I have made a simple database which includes one table and one form. The form and table has a date field in which I want a message box reminder to pop up when the current date is 7 days past the date in that date field. I not sure how to implement this.Any suggestions. Thanks.

 
Old June 26th, 2004, 11:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hello,

If you simply wanted to see if the date in your bound textbox has expired, you could do:

Private Sub Form_Current()
    If Date > Me.TicklerDate + 7 Then
        MsgBox Prompt:="Record has expired.", _
               Buttons:=vbExclamation Or vbOKOnly, _
               Title:="Reminder"
    End If
End Sub

If you have mutiple records in your form's record source, the Current event will evaluate the date field each time you navigate to a new record.

If it is likely that multiple records could be expired at any given moment, you may simply want to flag them all when you open the form, and tuck them away for further processing, like:


' Behind your form module
Private Sub Form_Open(Cancel As Integer)
    Call CheckDate
End Sub


' In a standard module
Sub CheckDate()
    On Error GoTo ErrorHandler

    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strSQL As String

    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    strSQL = "SELECT TicklerID, TicklerDate FROM tblTickler"
    rst.Open strSQL, cnn, adOpenStatic, adCmdText
    rst.MoveFirst

   ' Loop through multiple records, flagging each expired records
    Do Until rst.EOF
        If Date > rst!TicklerDate + 7 Then
            ' Display information about current record
            MsgBox Prompt:="Record " & rst!TicklerID & " has expired.", _
                   Buttons:=vbExclamation Or vbOKOnly, _
                   Title:="Reminder"

            ' Store expired record for further processing (recordset, array, collection, etc,)...
        End If
        rst.MoveNext
    Loop

   ' Clean up
    rst.Close
    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing
    Exit Sub

ErrorHandler:
    ' Clean up
    If Not rst Is Nothing Then
        If rst.State = adStateOpen Then rst.Close
    End If
    Set rst = Nothing

    If Not cnn Is Nothing Then
        If cnn.State = adStateOpen Then cnn.Close
    End If
    Set cnn = Nothing

    If Err <> 0 Then
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If

End Sub

HTH,

Bob

 
Old June 26th, 2004, 12:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Also like,

Private Sub Form_Current()
    If Me.TicklerDate <= DateAdd("d", -7, Date) Then
        MsgBox Prompt:="Record has expired.", _
               Buttons:=vbExclamation Or vbOKOnly, _
               Title:="Reminder"
    End If
End Sub



The expression <= DateAdd("d", -7, Date) is how you say "7 days ago or more" with date functions.

HTH,

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use message box? andy hee ASP.NET 1.0 and 1.1 Basics 1 April 18th, 2006 04:53 AM
message box nalla ASP.NET 2.0 Professional 4 December 23rd, 2005 03:00 AM
Yes No Message box dbartelt Access 7 October 28th, 2005 08:16 AM
Message Box HELP!!! Dwizz ASP.NET 1.0 and 1.1 Basics 1 July 21st, 2005 07:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.