473,509 Members | 3,032 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 11935
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
6654
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...
3
6351
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...
1
4069
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...
21
9119
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...
0
1849
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...
3
2250
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...
0
1279
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...
3
7644
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,...
1
2354
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...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
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,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5652
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,...
1
5060
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...
0
4730
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...
0
3216
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...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.