Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2023
    Posts
    3

    DateAdd function into VB

    Hello Forum Members
    I would like to get some help here.
    This screen shot is a form and the valid alert is =DateAdd("m",-9,[Valid])

    And I have a popup reminder as follows.
    When I use the Valid property, it works.
    But how can I use the Valid Alert function (DateAdd("m",-9,[Valid]) into the VB?


    / code starts here. /
    Private Sub Form_Timer()


    Dim ID As Long


    ID = Nz(DLookup("ID", "CPR_Biopsy", "Valid<=#" & Date & "#"), 0)
    If ID <> 0 Then
    DoCmd.OpenForm "CPR_Biopsy_Notice"
    End If


    ID = Nz(DLookup("ID", "CPR_Biopsy", "DateAdd("m",-9,[Valid] <=#" & Date & "#"), 0)
    If ID <> 0 Then
    DoCmd.OpenForm "CPR_Biopsy_Notice"
    End If




    End Sub

    /code ends here. /

    Thank you.
    Attached Thumbnails Attached Thumbnails DateAdd_01.jpg  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    In future, please place code between CODE tags to retain indentation and readability.

    What do you want to happen in VBA procedure? Do you want a MsgBox popup? Do you want to apply filter to form?
    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
    Join Date
    Mar 2023
    Posts
    3
    Hello June7

    Thank you for your quick reply.
    When I use the Valid property, CPR_Biopsy_Notice form opens. (yes, this is a popup form.)
    But now,
    the Valid Alert function (DateAdd("m",-9,[Valid]) does not open CPR_Biopsy_Notice form.

    Also, this
    CPR_Biopsy_Notice form has the following event procedure to open CPR_Biopsy form. (yes, this form is filtered.)
    So, once I figure out the
    Valid Alert function (DateAdd("m",-9,[Valid]) in the above VB, I can simply adjust it into the VB below as well.

    Is there a work-around for this problem?

    Thank you.

    Code:
    
    
    Code:
    Private Sub Open_CPR_Biopsy_Click()
    
    
        DoCmd.OpenForm "CPR_Biopsy", , , "Valid<=#" & Date & "#"
        DoCmd.Close acForm, Me.Name, asSaveYes
    
    
    End Sub



  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Still not sure what you want. Perhaps:
    Code:
    DoCmd.OpenForm "CPR_Biopsy", , , "DateAdd('m',-9,[Valid])<=Date()"
    You posted code for form Timer event. Why are you using this event?

    You mention a Valid Alert function but do not show any code for such a function, just an expression using DateAdd().

    There is not a "Valid" property, this is a field.
    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.

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Not really sure what your field and control names are.
    Since you have Valid Alert on your form, why not use that?

    Code:
    DoCmd.OpenForm "CPR_Biopsy", , , "Valid <= #" & Me.ValidAlert & "#"
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    Join Date
    Mar 2023
    Posts
    3
    Hello June 7 and Moke123

    Thank you for your suggestions.
    I simply want to use timer event as a reminder message to open a form.

    Code:
        ID = Nz(DLookup("ID", "CPR_Biopsy", "DateAdd('m',-9,[Valid])<=#" & Date & "#"), 0)    If ID <> 0 Then
            DoCmd.OpenForm "CPR_Biopsy_Notice"
        End If
    Then, I can open this form with a button click, and this form opens a different form with specific records.
    Code:
    DoCmd.OpenForm "CPR_Biopsy", , , "DateAdd('m',-9,[Valid])<=Date()"
    Now, it is working as expected.
    Once again, thank you so much for your help!

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

Similar Threads

  1. DateAdd Function
    By banno1 in forum Access
    Replies: 1
    Last Post: 08-02-2018, 11:54 AM
  2. Dateadd function
    By JackieFeng in forum Access
    Replies: 2
    Last Post: 05-02-2016, 10:48 AM
  3. DateAdd Function?
    By zburns in forum Reports
    Replies: 7
    Last Post: 06-23-2015, 01:55 PM
  4. DateAdd Function
    By jschlapi in forum Forms
    Replies: 4
    Last Post: 10-23-2013, 01:36 PM
  5. DateAdd Function
    By Desstro in forum Programming
    Replies: 3
    Last Post: 04-03-2011, 01:45 PM

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