473,586 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BeforeUpdate cancel intermittently not working - my fault or not?

24 New Member
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 2359
PianoMan64
374 Recognized Expert Contributor
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
4032
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 to the next record. So, in the BeforeUpdate event of the form itself I have the following code:
4
11523
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 its original value. The on change event is wrong for this, since the new data has already been saved. As I undertand it, the beforeupdate event...
9
3367
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
14813
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 the combobox I have some code to check the value against some criteria and if the new selected value fails the criteria, I cancel the BeforeUpdate...
6
3119
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 programmer), I finally figured out that the place to put the validations is in Form_BeforeUpdate. I have 2 questions: 1) once I determine there is an...
6
7591
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 before the user moves off the form to a subform on the main form, regardless of whether the end user even put focus to any of the four form fields. ...
8
4094
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 case that table is already created, and the combo box value is to be changed again, the temp. table needs to be deleted and the form needs to be...
2
2673
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 form, I have a listbox showing all the records in the table. The user can double-click the listbox to jump to that record via this code: ...
11
3454
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 Form_Load() Dim ctl As Control For Each ctl In Me.Controls If Left(ctl.Name, 3) = "Day" Then '??? ctl.BeforeUpdate = "=CheckDay(""" &...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.