473,396 Members | 1,783 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,396 software developers and data experts.

Problem with On Error Go to in Event Procedure

Hi Everyone,

I have created two tables. Both tables have three fields in them, one
of the fields in each of the tables is a Key. The two tables have a
1-1 relationship setup with referential integerity, cascading delete
and update enforced.

I have created a form for each table to enter data into them. On the
forms I also have a button which closes the form, so the user can close
the form by closing the window (ie click on the X in the upper right
corner of the window) or the user can click on the close button I have
created. The code for the close button follows:

Private Sub Submit_Click()

On Error GoTo Err_Submit_Click

DoCmd.Close

Exit_Submit_Click:
Exit Sub

Err_Submit_Click:
MsgBox Err.Description
Resume Exit_Submit_Click

End Sub

Now heres my problem - if the user enters information on the record
that violates referential integerity and then clicks on the windows
close (ie the X) then Access will flag this as an error telling the
user that they cannot do this. Great. On the other hand if the user
clicks on the Button that I created, the form will close, but Access
will not give the errors - it does everything correctly just does not
display the errors.
If I set a break in debug and step through the code it will show the
errors, but if it is just allowed to run it does not even go to the
error routine.
I have already tried putting the code

DoCmd.SetWarnings True

in, but that did not help.
Any help would be welcome, thanks in advance.

Richard

Jan 29 '06 #1
3 4142
Yes, after 13 years, Access *still* loses your data without warning, exactly
as you say.

Once you know about this data-loss bug, it's easy enough to work around it.
*Always* explicitly save before you use the close method/action on a bound
form, e.g.:
If Me.Dirty Then Me.Dirty = False

If the record cannot be saved, that line will generate an error, so your
routine drops to the error handler, and the Close is never executed.

More info:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

I am convinced that this is one of the bugs that gives Access a bad
reputation as "unreliable". People don't figure out what went wrong: they
just know they entered something that Access "lost".

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<be***@bvu.edu> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi Everyone,

I have created two tables. Both tables have three fields in them, one
of the fields in each of the tables is a Key. The two tables have a
1-1 relationship setup with referential integerity, cascading delete
and update enforced.

I have created a form for each table to enter data into them. On the
forms I also have a button which closes the form, so the user can close
the form by closing the window (ie click on the X in the upper right
corner of the window) or the user can click on the close button I have
created. The code for the close button follows:

Private Sub Submit_Click()

On Error GoTo Err_Submit_Click

DoCmd.Close

Exit_Submit_Click:
Exit Sub

Err_Submit_Click:
MsgBox Err.Description
Resume Exit_Submit_Click

End Sub

Now heres my problem - if the user enters information on the record
that violates referential integerity and then clicks on the windows
close (ie the X) then Access will flag this as an error telling the
user that they cannot do this. Great. On the other hand if the user
clicks on the Button that I created, the form will close, but Access
will not give the errors - it does everything correctly just does not
display the errors.
If I set a break in debug and step through the code it will show the
errors, but if it is just allowed to run it does not even go to the
error routine.
I have already tried putting the code

DoCmd.SetWarnings True

in, but that did not help.
Any help would be welcome, thanks in advance.

Richard

Jan 29 '06 #2
"be***@bvu.edu" <be***@bvu.edu> wrote in
news:11**********************@g43g2000cwa.googlegr oups.com:
Hi Everyone,

I have created a form for each table to enter data into them.
On the forms I also have a button which closes the form, so
the user can close the form by closing the window (ie click on
the X in the upper right corner of the window) or the user can
click on the close button I have created.> Now heres my problem - if the user enters information on the
record that violates referential integerity and then clicks on
the windows close (ie the X) then Access will flag this as an
error telling the user that they cannot do this. Great. On the
other hand if the user clicks on the Button that I created,
the form will close, but Access will not give the errors - it
does everything correctly just does not display the errors.
If I set a break in debug and step through the code it will
show the errors, but if it is just allowed to run it does not
even go to the error routine.
Any help would be welcome, thanks in advance.

First you should validate the integrity of the data in the
form's BeforeUpdate event, not wait till the Close event.

--
Bob Quintal

PA is y I've altered my email address.
Jan 29 '06 #3
Thanks Allen,

That worked just great.

Richard

Jan 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
2
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which...
16
by: Steve Jorgensen | last post by:
I'm trying to figure out if there is a way to generate standard error handlers that "know" if the calling code has an error handler in effect (On Error Goto <label> or On Error Resume Next) before...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
3
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
7
by: Peter D.C. | last post by:
Hi I want to update data hold in several textbox controls on an asp.net form. But it seems like it is the old textbox values that is "re-updates" through a stored procedure who updates a SQL...
4
by: Bass Pro | last post by:
Hi, I am creating textbox, radiobuttonlist and checkboxlist dynamically depending on data from a table. It is a questionnaire. I add the control on a Panel control during the 1st load_page event....
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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
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...
0
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,...
0
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...

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.