Results 1 to 5 of 5
  1. #1
    vad77 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Location
    USA
    Posts
    101

    Changing fields using an AfterUpdate event

    I am interested to know if there is a better way of doing the the following updates.
    I have the following fields on my form. They could be Null or have previous values.



    HPAprroval - Verbal, Pending or Approved (Yes I know when I created my table I had a typo on the field name)
    HRApprovalReqDate
    HRApprovalDate.

    If I change the HRApprovalReqDate I want it to change the HRAprroval to "Prending" and set the HRApproval date to NULL
    When I enter a date in the HRAppoval date it will then change HRAprroval to "Approved".

    On the AfterUpdate event of HRApprovalReqDate I have the following code.

    Private Sub HRApprovalReqDate_AfterUpdate()
    Me.HRAprroval.Value = "Pending"
    Me.HRApprovalDate.Value = ""
    End Sub

    This works

    In the AfterUpdate event of HRApprovalDate I have the following.


    Private Sub HRApprovalDate_AfterUpdate()
    Me.HRAprroval = "Approved"
    End Sub

    This also works but I am wondering if there is a better way to accompish these changes. One problem I can see is if I need to just wipe out the Approval date for what ever reason it then always change my HRApproval to Approve.
    There might be an instance where my HRApproval is set to "Pending", if I remove the approval date it will then change HRP Approval to Approved when it needs to stay as Pending.
    Thanks in advance for your repsonses.

    Vito

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Saving calculated data is usually unnecessary and often bad design.

    The status can be calculated based on whether or not the date fields have value. There is no need to store the status.

    The 'verbal' parameter is oddity. Under what condition does it apply?


    If IsNull(HRAprroval) Then
    Me.HRAprroval = "Pending"
    Else
    Me.HRAprroval = "Approved"
    End If


    BTW, changing the field name shouldn't be too difficult.
    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
    vad77 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Location
    USA
    Posts
    101
    Thanks again June7, I originally was going to go with 3 command button to change approval status and the buttons are still on my form. It was my manager that made the request to change status when the date is added or changed. I would rather stay with the command button and just add code to null out the date on the HRApproval date field. I can see issues with haveing code in the AfterUpdate event of my date fields.
    But let me ask another question. I have done MsgBox before but can I program my "Approved" command button to set HRApproval to "Approved" and then have an input box pop-up and ask for an approval date and store that value in the HRApprovalDate field?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Yes, but using popups for data entry is tricky. Validating the input can be a challenge. Example:
    Code:
                strInput = "?"
                While strInput = "?"
                    strInput = InputBox("Select Flat-Elongated ratios to test." & vbCrLf & vbCrLf & _
                    "     3     1:3" & vbCrLf & vbCrLf & _
                    "     5     1:5" & vbCrLf & vbCrLf & _
                    "     B     Both")
                    If strInput = "3" Or strInput = "5" Or strInput = "B" Then
                        Condition = UCase(strInput)
                    Else
                        MsgBox "Not an appropriate entry.", vbApplicationModal, "Entry Error"
                        strInput = "?"
                    End If
                Wend
    Again, just calculating the status descriptor when needed is possible and really easier.
    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
    vad77 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Location
    USA
    Posts
    101
    That is what I thought, I'll stick with my simple solution it's not like these fileds get updated every day.
    The command buttons I have work just fine. I just added a line to my Pending button to remove that approval date.
    Thanks one more time June7.
    i'll just leave this thread open for one more day.

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

Similar Threads

  1. Form AfterUpdate Event
    By RayMilhon in forum Forms
    Replies: 2
    Last Post: 09-09-2011, 09:20 AM
  2. AfterUpdate event help
    By 10 Gauge in forum Forms
    Replies: 11
    Last Post: 09-08-2011, 10:04 AM
  3. AfterUpdate event code error?
    By agripa86 in forum Programming
    Replies: 3
    Last Post: 08-12-2011, 09:12 AM
  4. how to created afterupdate event
    By Brigitt in forum Forms
    Replies: 2
    Last Post: 02-15-2011, 03:23 AM
  5. AfterUpdate event won't refresh subform!
    By Remster in forum Forms
    Replies: 16
    Last Post: 11-26-2010, 10:06 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