Preventing the insertion of a row

L

Laurel

I have a form which creates a new reow with default data and allows the user
to enter the key column value. If the user choose to close the form without
entering a required column value (e.g., they opened the form and changed
their mind), I get an error because of the empty column. It's a referential
issue.

How can I stop the attempted insertion of that row if no data has been
entered in this field? I'm using code. I tried to execute
DoCmd.CancelEvent in the BeforeUpdate event.... no luck.
 
M

Michel Walsh

Hi,


In the BeforeUpdate event of the FORM, you can type


Cancel= True


but you just cancel the record save; the record will still be dirty and
that will err the form attempt to close. You have to UNDO the form to remove
the record appending:


Me.Undo


which cancel the unsaved-job done up to this point, here, that would
cancel the record append. You can close the form after.

Note that you may have to use the form onError event in some scenario.



Hoping it may help,
Vanderghast, Access MVP
 
L

Laurel

Note that you may have to use the form onError event in some scenario.

Thanks. Looks like good stuff. One question... If I get to the onError
event, how do I know which error got me there? Is there a list of error
numbers for VB somewhere?
 
M

Michel Walsh

Hi,


OnError has an argument that gives you the error number that occurred,
DataErr.

The easiest way is to "break" into that event (since Access 2000, just
type


Debug.Assert False


and execution would break at that point, unconditionally), then, to run
the scenario you are interested, and once the "break" occur, examine the
DataErr value!


There is a knowledge (
http://support.microsoft.com/default.aspx?scid=fh;EN-US;kbhowto&sd=GN&ln=EN-US&FR=0)
article (105666) that gives you a way to generate all the possible errors
and their description message, but the list is so large, it is practically
unpractical... :)


Hoping it may help,
Vanderghast, Access MVP
 
L

Laurel

Great, thanks for the tip and url.

Michel Walsh said:
Hi,


OnError has an argument that gives you the error number that occurred,
DataErr.

The easiest way is to "break" into that event (since Access 2000, just
type


Debug.Assert False


and execution would break at that point, unconditionally), then, to run
the scenario you are interested, and once the "break" occur, examine the
DataErr value!


There is a knowledge (
http://support.microsoft.com/default.aspx?scid=fh;EN-US;kbhowto&sd=GN&ln=EN-
US&FR=0)
article (105666) that gives you a way to generate all the possible errors
and their description message, but the list is so large, it is practically
unpractical... :)


Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top