Results 1 to 2 of 2
  1. #1
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    82

    Why is this code resulting in an update?

    Hi all,

    I have a form with a checkbox showing whether an employee is currently active or away on leave. If they try to mark the employee active and there is leave, they get a message box telling them to edit the leave. It then cancels their change. When I change records, it tries to update the record, even though there is no update. This causes a few errors down the road if they try to go edit the leave period. Here's the code:



    Code:
    Private Sub chkActive_BeforeUpdate(Cancel As Integer)
        If chkActive = -1 Then
            If DCount("ID", "tblAbsence", "EmpNo= " & Me.EmpNo & " AND Description = ""Away"" AND Format(ExpectedDateAway,""Short Date"") <= Format(Now(),""Short Date"") AND Format(ExpectedDateBack, ""Short Date"") >= Format(Now(),""Short Date"")") <> 0 Then
                'LEAVE DURING THIS PERIOD EXISTS
                MsgBox "This employee is currently inactive due to leave. Please edit their leave to return to active status.", vbCritical, "Employee is on Leave"
                Cancel = True
                Me.chkActive.Undo
                Exit Sub
            End If
        End If
    End Sub
    Thanks,

    Scott

  2. #2
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    82
    I figured it out. I changed me.chkActive.undo to me.undo.

    All good.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-15-2016, 02:47 PM
  2. update VBA 2.0 code in forms into access 7.0 code
    By toughwg in forum Programming
    Replies: 1
    Last Post: 12-08-2015, 11:40 AM
  3. Replies: 9
    Last Post: 01-14-2015, 05:10 PM
  4. DSUM is not resulting
    By azhar2006 in forum Forms
    Replies: 1
    Last Post: 08-16-2014, 05:10 PM
  5. Replies: 2
    Last Post: 06-28-2013, 12:58 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