473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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?

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
1 2348
PianoMan64
374 Expert 256MB
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

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

Similar topics

4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
4
by: bob bob via AccessMonster.com | last post by:
I'm sure this is a simple one. I have a combo box that, when its data is changed, will trigger a second form to open for input. If the operator declines input, I want the combo box to return to...
9
by: simonmarkjones | last post by:
I want to call a function which does this when the next record button is pressed (calling it from before update) if textboxes are empty then Message box you must fill text box
2
by: PC Datasheet | last post by:
In a form/subform I have an unbound combobox in the form header that sets the value of a field in the subform so that it does not have to be entered for each record. In the BeforeUpdate event of...
6
by: lorirobn | last post by:
Hi, I have a form with a continuous subform. I am working on putting validations in for the subform's required fields. Being somewhat new to Access (or rather, an antiquated mainframe...
6
by: tlyczko | last post by:
I have a BeforeUpdate where I need to ensure that no matter what, the first four fields on the form (one text box, 3 combo box lists) have data entered in them before the user closes the form or...
8
by: Michael R | last post by:
Dear users and experts, An unbound combo box in my form is responsible for changing a city name for an update query that creates a temprorary table which the form uses as its record source. In...
2
by: thatguyNYC | last post by:
Hello-- I have a form that lets the user edit the values in a lookup table. The form is bound to a table and has one textbox on it. The record nav buttons are enabled. On the top half of the...
11
by: ChipR | last post by:
I have a generic AfterUpdate function applied to my 14 text boxes in a continuous subform, but I can't figure out the syntax to do BeforeUpdate with Cancel. Is this even possible? Private Sub...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.