BeforeUpdate cancel intermittently not working - my fault or not?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pelicanstuff
    New Member
    • Nov 2007
    • 24

    BeforeUpdate cancel intermittently not working - my fault or not?

    Below is my code. Me.Confirmed is a checkbox. Sometimes the cancel at line 37 works when the user clicks "no", someetimes it doesn't.

    Is this my fault or someting else?

    Code:
    Private Sub Confirmed_BeforeUpdate(Cancel As Integer)
    If gcfHandleErrors Then On Error GoTo PROC_ERR
    PushCallStack "ConfirmDeployment"
    
    Dim strfield As String
    strfield = Me.ConsultantID & ""
    If StrPtr(strfield) = 0 Or Len(strfield) = 0 Then
    MsgBox "Cannot confirm deployment as no Consultant has been selected", vbCritical, "title"
    Me.Undo
    Cancel = True
    GoTo PROC_EXIT
    End If
    
    
    Dim Msg1, Style1, Title1, Response1
    
    If Me.Confirmed = True Then
    Msg1 = "Are you sure that you want to confirm deployment of consultant to this Job?"
    Msg1 = Msg1 & vbCrLf & "Make sure this is what you want to do."
    End If
    
    If Me.Confirmed = False Then
    Msg1 = "Are you sure that you want to cancel deployment of consultant to this Job?"
    Msg1 = Msg1 & vbCrLf & "Make sure this is what you want to do."
    End If
    
    Style1 = vbYesNo + vbQuestion + vbDefaultButton2
    Title1 = "Confirm "
    
    Response1 = MsgBox(Msg1, Style1, Title1)
    
            If Response1 = vbYes Then
            GoTo PROC_EXIT
            
            Else
            Me.Undo
            Cancel = True
            GoTo PROC_EXIT
            End If
    
    
    PROC_EXIT:
      PopCallStack
      Exit Sub
    
    PROC_ERR:
      GlobalErrHandler
      Resume PROC_EXIT
    End Sub
  • PianoMan64
    Recognized Expert Contributor
    • Jan 2008
    • 374

    #2
    Originally posted by pelicanstuff
    Below is my code. Me.Confirmed is a checkbox. Sometimes the cancel at line 37 works when the user clicks "no", someetimes it doesn't.

    Is this my fault or someting else?

    [CODE=VB]Private Sub Confirmed_Befor eUpdate(Cancel As Integer)
    If gcfHandleErrors Then On Error GoTo PROC_ERR
    PushCallStack "ConfirmDeploym ent"

    Dim strfield As String
    strfield = Me.ConsultantID & ""
    If StrPtr(strfield ) = 0 Or Len(strfield) = 0 Then
    MsgBox "Cannot confirm deployment as no Consultant has been selected", vbCritical, "title"
    Me.Undo
    Cancel = True
    GoTo PROC_EXIT
    End If


    Dim Msg1, Style1, Title1, Response1

    If Me.Confirmed = True Then
    Msg1 = "Are you sure that you want to confirm deployment of consultant to this Job?"
    Msg1 = Msg1 & vbCrLf & "Make sure this is what you want to do."
    End If

    If Me.Confirmed = False Then
    Msg1 = "Are you sure that you want to cancel deployment of consultant to this Job?"
    Msg1 = Msg1 & vbCrLf & "Make sure this is what you want to do."
    End If

    Style1 = vbYesNo + vbQuestion + vbDefaultButton 2
    Title1 = "Confirm "

    Response1 = MsgBox(Msg1, Style1, Title1)

    If Response1 = vbYes Then
    GoTo PROC_EXIT

    Else
    Me.Undo
    Cancel = True
    GoTo PROC_EXIT
    End If


    PROC_EXIT:
    PopCallStack
    Exit Sub

    PROC_ERR:
    GlobalErrHandle r
    Resume PROC_EXIT
    End Sub[/CODE]
    From the looks of the code, there are alot of variables that could cause you problems. The Main one that sticks out at me is the gcfHandleErrors . Since you're conditionally setting the OnError Option, then you're going to have mixed results based on the value of gcfHandleErrors .

    I don't understand the reason for conditionally setting the OnError, but if you can explain that to me and how the value of gcfHandleErrors is used, that may help me understand what you're trying to do.

    The other thing that I have to comment about is it is NEVER good practice to Update the table and then ask, is this what you really wanted to do?

    That may be MOST of your problem there. Just keep in mind that ask before making any changes to the data, will always help you when it comes to dealing with customers that may no know your interface that well.

    Hope that helps,

    Joe P.

    Comment

    Working...