473,668 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cancel = True not working??

283 Contributor
Hello everyone,

Well I am having a small problem with canceling an action and keeping the focus on the text box with the problem.

To give some details as to what im trying to do. What i have is a form where I have an error box pop up if you are going to duplicate a record on the table. I have the event in the BeforeUpdate of the text box. So if there is a duplication (cancel = true). Now from everything I have been reading if you have the cancel = true function it should keep the focus on the current text box that has a problem but on my form it is not. It just alerts you with the pop up box and then continues on to the next text box. I want to make it so that if the error box pops up (which you can only press ok on) then it will keep the focus of the text box that the error occured instead of continuing on to the next text box.

Any help would be great thanks so much :)

code im working with

Expand|Select|Wrap|Line Numbers
  1. Private Sub Text9_BeforeUpdate(Cancel As Integer)
  2. On Error GoTo Err_Text9_BeforeUpdate
  3.  
  4. If DCount("*", _
  5.           "[MainTable]", _
  6.           "(([Date]=#" & Format(Me.Text3, "mm/dd/YYYY") & "#) AND (" & _
  7.           "[Block1]=" & Chr(34) & Me.Text9 & Chr(34) & "))") > 0 Then
  8.  
  9.     LResponse = MsgBox("A Record Of This Block On This Date Already Exists.", vbOKOnly + vbQuestion, "Record Duplication Error")
  10.      LResponse = vbOK
  11.         Cancel = True
  12.         End If
  13.  
  14. Exit_Text9_BeforeUpdate:
  15.     Exit Sub
  16.  
  17. Err_Text9_BeforeUpdate:
  18.     MsgBox Err.Description
  19.     Resume Exit_Text9_BeforeUpdate
  20.  
  21.  
Aug 16 '10 #1
3 11967
Jerry Maiapu
259 Contributor
Try:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Text9_BeforeUpdate(Cancel As Integer)
  2.  On Error GoTo Err_Text9_BeforeUpdate
  3.  
  4.  If DCount("*", _
  5.           "[MainTable]", _
  6.            "(([Date]=#" & Format(Me.Text3, "mm/dd/YYYY") & "#) AND (" & _
  7.            "[Block1]=" & Chr(34) & Me.Text9 & Chr(34) & "))") > 0 Then
  8.  
  9.       MsgBox"A Record Of This Block On This Date Already Exists.", vbOKOnly + vbQuestion, "Record Duplication Error"
  10.          Cancel = 1
  11.           Me.Text9.setfocus
  12.          Exit sub
  13.          End If
  14.  
  15.  Exit_Text9_BeforeUpdate:
  16.      Exit Sub
  17.  
  18.  Err_Text9_BeforeUpdate:
  19.      MsgBox Err.Description
  20.      Resume Exit_Text9_BeforeUpdate
Aug 17 '10 #2
slenish
283 Contributor
Hi Jerry,

Thanks for the reply. I tried your idea and still am getting the same problem but I took what you added and then moved the entire code to the AfterUpdate function and now it works....not sure why it wont work in the before update but it works now :D

Thanks again for the help
Aug 17 '10 #3
Jerry Maiapu
259 Contributor
...not sure why it wont work in the before update but it works now :D

I did not notice that too.
Well if you see (logic) Before update will fire before putting the value in Text9. After Update will fire after Text9 has a value.

For example if you what to stop people entering value into Text9 if say Text8 is blank then
you can use Before update of Text9 to check if there exist a value in Text8.

In your case, you want to perform something after Text9 has a value.

Anyway, I'm glad my solution was helpful

Jerry
Aug 17 '10 #4

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

Similar topics

6
6664
by: Arno R | last post by:
Hi all I come across a 'feature' of Access (2000) that I don't like and would like to disable. I am checking if a value already exists in a table. I a subform I use code like : Private Sub Choice_BeforeUpdate(Cancel As Integer) If <validation on inputted value already in table is true> Then MsgBox "This choice already exists...", vbCritical, "Validation" Cancel = True
3
6366
by: Oenone | last post by:
I'm writing an application with various MDI child forms. In the Closing event of many of the forms, I have code that asks the user whether he is sure he wants to close the form, because it contains unsaved data. If the user clicks "No" then the code sets e.Cancel = True, which cancels the closure. This works just great. But when the user closes the MDI parent form, the cancellation seems to be completely ignored. The MessageBox...
1
4077
by: Phill W. | last post by:
Has any come across a situation where, in a Form-derived .. er .. Form, the Event Arguments passed to OnClosing /already/ have their Cancel argument set to True? Protected Overrides Sub OnClosing( _ ByVal e As System.ComponentModel.CancelEventArgs _ ) Debug.WriteLine("e.Cancel=(" & e.Cancel.ToString() & ")") ' It's True already !!
21
9156
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
0
1853
by: tim.cavins | last post by:
I am trying a GridView for the first time and it seems to be something that should be EXTREMELY simple. I cannot get the Update or Cancel when trying to edit a row to work. When I click on the Edit link, the row comes up in Edit mode. That's as far as it goes. If I change a value in a textbox and click Update, the page reloads still in edit mode but the original values appear in the textboxes.
3
2257
by: Birky | last post by:
Hello, I’m hoping you can help me out with two issues I’m having with my code. I have an Access Report named Report_Project_Event_Log which I have calling a Form named “Custom_Code_lookup” which allows a user to select data for the report. I have a hidden txt object within this form named txtContinue which is either set to “no” or “yes”. I believe I have everything running correctly except for my cancel code below. When the Cancel button is...
0
1288
by: bill crawley | last post by:
Hi All, I am using a Wizard control that has 13 steps so far. On one of the Steps I may set e.cancel = true in the nextbutton click event (this happens to be when ActiveStepIndex=2). Whilst experimenting if I set e.cancel=true at any point when activestepindex is < 4 the browser always crashed whilst activestepindex moves between 4 and 5. If I dont set e.cancel = true then the control works fine. I then removed my code from the nextbutton...
3
7647
by: Smithers | last post by:
In consideration of the brief sample code at the following link... http://msdn2.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx .... when we set e.Cancel = true, How does the form subsequently know to NOT close the form? More generally, after an event is raised, does the event raising class somehow retain a reference to the CancelEventArgs instance, and then check the value of the .Cancel property to...
1
2360
by: pelicanstuff | last post by:
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? Private Sub Confirmed_BeforeUpdate(Cancel As Integer) If gcfHandleErrors Then On Error GoTo PROC_ERR PushCallStack "ConfirmDeployment" Dim strfield As String strfield = Me.ConsultantID & ""
0
8381
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8799
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6209
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2026
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.