How to Exit a form with no update and no prompt avoiding the beforeupdate trigger

harleyskater

IT Manager
Local time
Today, 01:31
Joined
Oct 29, 2007
Messages
95
I have a timeclock that I built into my access program. That just allows employees to clockin and out. I needed to ask how to automatically through VBA when a form is closed from a click of the [X] in the upper right hand corner how to cancel the changes that are waiting to be updated in the DB. This is the code I have so far, but this is more for the button I have in my form the "clockin button" that updates the record with the information. I want to be able to allow the person to hit the X and exit the form with no prompts and no updates. This is the code I have so far.

So what I am hoping for is a code that cancels the update from the exit or close trigger that skips the beforeupdate trigger all together. Any suggestions? !: ) : )

Code:
Option Compare Database

Dim LTotal As Long

Private Sub Command15_Click()

    DoCmd.Close

End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)

LTotal = DCount("emp_id", "employee clockin Query", "emp_id = " & emp_id & "") ' if 1+  already clocked in
    
    If LTotal > 0 Then
            MsgBox "You have not Clocked Out " & emp_first & "", _
            vbExclamation, "Please ClockOut."
            Cancel = True
            Exit Sub
    End If
    
    lngAnswr = MsgBox("Is your Entry Correct " & emp_first & "?", vbOKCancel + vbQuestion)
    If lngAnswr = vbOK Then
        Cancel = False
        MsgBox ("ClockIn Confirmed " & emp_first & "")
    Else    ' User chose No.
        Cancel = True
        MsgBox ("ClockIn Canceled " & emp_first & "")
    End If

End Sub
 
Set a public flag when you open the form and reset it with your close button. If it is not reset then the user used the [X] to close the form so you can just do a Me.UnDo to clear any changes to the form.
 
Sounds like a plan, I don't know anything about the subject you are talking about. I will research it, If you feel like shedding a little more light on the subject that would be appreciated :) Thank you for your response !

Set a public flag when you open the form and reset it with your close button. If it is not reset then the user used the [X] to close the form so you can just do a Me.UnDo to clear any changes to the form.
 
It looks like you are getting the same assistance on UA. I'll let Steve handle it.
 
Yes they posted some code, thanks for the update :) I get automatic updates from here default, but I always forget to click the updates on UA. Code is goood :) haha thank you
It looks like you are getting the same assistance on UA. I'll let Steve handle it.
 

Users who are viewing this thread

Back
Top Bottom