By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

BeforeUpdate cancel intermittently not working - my fault or not?

P: 24
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?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Confirmed_BeforeUpdate(Cancel As Integer)
  2. If gcfHandleErrors Then On Error GoTo PROC_ERR
  3. PushCallStack "ConfirmDeployment"
  4.  
  5. Dim strfield As String
  6. strfield = Me.ConsultantID & ""
  7. If StrPtr(strfield) = 0 Or Len(strfield) = 0 Then
  8. MsgBox "Cannot confirm deployment as no Consultant has been selected", vbCritical, "title"
  9. Me.Undo
  10. Cancel = True
  11. GoTo PROC_EXIT
  12. End If
  13.  
  14.  
  15. Dim Msg1, Style1, Title1, Response1
  16.  
  17. If Me.Confirmed = True Then
  18. Msg1 = "Are you sure that you want to confirm deployment of consultant to this Job?"
  19. Msg1 = Msg1 & vbCrLf & "Make sure this is what you want to do."
  20. End If
  21.  
  22. If Me.Confirmed = False Then
  23. Msg1 = "Are you sure that you want to cancel deployment of consultant to this Job?"
  24. Msg1 = Msg1 & vbCrLf & "Make sure this is what you want to do."
  25. End If
  26.  
  27. Style1 = vbYesNo + vbQuestion + vbDefaultButton2
  28. Title1 = "Confirm "
  29.  
  30. Response1 = MsgBox(Msg1, Style1, Title1)
  31.  
  32.         If Response1 = vbYes Then
  33.         GoTo PROC_EXIT
  34.  
  35.         Else
  36.         Me.Undo
  37.         Cancel = True
  38.         GoTo PROC_EXIT
  39.         End If
  40.  
  41.  
  42. PROC_EXIT:
  43.   PopCallStack
  44.   Exit Sub
  45.  
  46. PROC_ERR:
  47.   GlobalErrHandler
  48.   Resume PROC_EXIT
  49. End Sub
Mar 11 '08 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 374
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?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Confirmed_BeforeUpdate(Cancel As Integer)
  2. If gcfHandleErrors Then On Error GoTo PROC_ERR
  3. PushCallStack "ConfirmDeployment"
  4.  
  5. Dim strfield As String
  6. strfield = Me.ConsultantID & ""
  7. If StrPtr(strfield) = 0 Or Len(strfield) = 0 Then
  8. MsgBox "Cannot confirm deployment as no Consultant has been selected", vbCritical, "title"
  9. Me.Undo
  10. Cancel = True
  11. GoTo PROC_EXIT
  12. End If
  13.  
  14.  
  15. Dim Msg1, Style1, Title1, Response1
  16.  
  17. If Me.Confirmed = True Then
  18. Msg1 = "Are you sure that you want to confirm deployment of consultant to this Job?"
  19. Msg1 = Msg1 & vbCrLf & "Make sure this is what you want to do."
  20. End If
  21.  
  22. If Me.Confirmed = False Then
  23. Msg1 = "Are you sure that you want to cancel deployment of consultant to this Job?"
  24. Msg1 = Msg1 & vbCrLf & "Make sure this is what you want to do."
  25. End If
  26.  
  27. Style1 = vbYesNo + vbQuestion + vbDefaultButton2
  28. Title1 = "Confirm "
  29.  
  30. Response1 = MsgBox(Msg1, Style1, Title1)
  31.  
  32.         If Response1 = vbYes Then
  33.         GoTo PROC_EXIT
  34.  
  35.         Else
  36.         Me.Undo
  37.         Cancel = True
  38.         GoTo PROC_EXIT
  39.         End If
  40.  
  41.  
  42. PROC_EXIT:
  43.   PopCallStack
  44.   Exit Sub
  45.  
  46. PROC_ERR:
  47.   GlobalErrHandler
  48.   Resume PROC_EXIT
  49. End Sub
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.
Mar 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.