Results 1 to 9 of 9
  1. #1
    Robert2150 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    104

    Automated Message Box notice when loading a form.

    I have a database that has a main form, and a sub-form (Service Contracts). The sub-form is filled in from a table based upon the property that is shown in the main form.

    I would like to generate a message based upon one of the fields being loaded in the sub-form. That field is "End Date".

    The bases for opening the message is that the "End Date" of the form record is less than the current Date.

    The message is "The Service Contract Has Expired."

    I have tried entering code in the "On Load" property of both the main form and the sub-form, to no avail.

    The code I have tried is:

    Private Sub Form_Load()
    If "EndDate" < Date Then
    MsgBox "Service Contract Has Expired"
    End If
    End Sub

    Any help would be appreciated. Thank you.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    So if this value is in each subform record, which record do you want to report on?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    the "End Date" of the form record is less than the current Date
    Which form?

    EDIT: Assuming you mean the main form, "EndDate" is a string. [EndDate] is a field or control name. That may be your problem.
    Maybe you should also use conditional formatting to flag that form control?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Robert2150 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    104
    Only the record that has the same "Property Number" (A field on both tables.) is loaded into the sub-form.

  5. #5
    Robert2150 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    104
    The "End Date" is a field.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    I don't understand. The subform has only 1 record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Robert2150 View Post
    I would like to generate a message based upon one of the fields being loaded in the sub-form. That field is "End Date".
    Code:
    Private Sub Form_Load()
    
        If [EndDate] < Date() Then
            MsgBox "Service Contract Has Expired"
        End If
    
    End Sub
    The "Form_Load" event is probably the wrong event. I would try using the "Form_Current" event.


    My preference would be to use a query and have a calculated column
    Code:
    IsExpired: IIF([EndDate] < Date(), "Service Contract Has Expired", "")
    then add a text box (to the sub form) bound to this query column.

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    The "End Date" is a field.
    When you write it like that, it is a string. Note ssanfu's omission of the space (which many of us practice). If it must be there, then it must be
    [End Date] not "End Date" and not End Date and not "[End Date]". The latter might be OK in a domain function, but not for what you're doing.

  9. #9
    Robert2150 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    104
    It depends, I have a query than only shows (loads) the record for the property selected for the Main Form.

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

Similar Threads

  1. Automated Email Truncating Message Body
    By sirhacksalot in forum Access
    Replies: 2
    Last Post: 12-03-2013, 01:21 PM
  2. Error message 'Error in Loading DLL'
    By rahayes in forum Programming
    Replies: 2
    Last Post: 09-22-2012, 05:17 AM
  3. Replies: 3
    Last Post: 08-03-2012, 02:26 PM
  4. How to create warning notice
    By bluepowa in forum Programming
    Replies: 3
    Last Post: 09-29-2009, 03:15 AM

Tags for this Thread

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