Results 1 to 5 of 5
  1. #1
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136

    Updating fields in form based on date field (part 2)

    Hi all. Below is the code I have to update some fields based on a date field. It's working the way I want but the users want nothing to happen when the date field is cleared/deleted. They just want the date to be gone and nothing else happens. Right now when the date is deleted it performs the action again. How/where do I add that code?

    Private Sub Date_Zipped_to_Mfg_AfterUpdate()
    If MsgBox("Are you sure?", vbYesNo, "Confirm") = vbNo Then Exit Sub
    With Me
    If Not IsNull(.Date_Zipped_to_Mfg) Then
    .Version_on_CDMS_and_Current_at_States = .Latest_Label_Released_for_Prod
    .Previous_Label_Version = .Latest_Label_Released_for_Prod
    .Latest_Label_Released_for_Prod = Null


    End If
    End With
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I would expect the IsNull() test to work, but try:

    If IsDate(.Date_Zipped_to_Mfg) Then

    instead. I'd move the message box code inside that test so the user doesn't get prompted unnecessarily.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    I'm not sure I fully understand your question, but add one line something like
    Code:
    Private Sub Date_Zipped_to_Mfg_AfterUpdate()
    
        If IsNull(Me.Date_Zipped_to_Mfg) Then Exit Sub
    
        If MsgBox("Are you sure?", vbYesNo, "Confirm") = vbNo Then Exit Sub
        With Me
            If Not IsNull(.Date_Zipped_to_Mfg) Then
                .Version_on_CDMS_and_Current_at_States = .Latest_Label_Released_for_Prod
                .Previous_Label_Version = .Latest_Label_Released_for_Prod
                .Latest_Label_Released_for_Prod = Null
            End If
        End With
    
    End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    This was it, thanks!

    Quote Originally Posted by Minty View Post
    I'm not sure I fully understand your question, but add one line something like
    Code:
    Private Sub Date_Zipped_to_Mfg_AfterUpdate()
    
        If IsNull(Me.Date_Zipped_to_Mfg) Then Exit Sub
    
        If MsgBox("Are you sure?", vbYesNo, "Confirm") = vbNo Then Exit Sub
        With Me
            If Not IsNull(.Date_Zipped_to_Mfg) Then
                .Version_on_CDMS_and_Current_at_States = .Latest_Label_Released_for_Prod
                .Previous_Label_Version = .Latest_Label_Released_for_Prod
                .Latest_Label_Released_for_Prod = Null
            End If
        End With
    
    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I'm curious how that helped avoid the update, since you were already using IsNull() to test that control before updating. It would avoid the message box, but I'd have gone a different way as I mentioned. Something like:

    Code:
        
        With Me
            If Not IsNull(.Date_Zipped_to_Mfg) Then
                If MsgBox("Are you sure?", vbYesNo, "Confirm") = vbNo Then Exit Sub
                .Version_on_CDMS_and_Current_at_States = .Latest_Label_Released_for_Prod
                .Previous_Label_Version = .Latest_Label_Released_for_Prod
                .Latest_Label_Released_for_Prod = Null
            End If
        End With
    If you stay with Minty's method, the second IsNull() test is unnecessary; you already know it isn't Null.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 11
    Last Post: 06-08-2022, 12:16 PM
  2. Replies: 5
    Last Post: 01-23-2021, 12:41 PM
  3. Replies: 3
    Last Post: 08-25-2016, 09:12 AM
  4. Replies: 1
    Last Post: 02-27-2015, 05:03 PM
  5. Updating one date field based on another
    By barryg80 in forum Forms
    Replies: 4
    Last Post: 04-19-2013, 03:17 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