By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,813 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Detecting when AutoNumber field = NULL

P: n/a
I'm having a problem with a form that uses AutoNumber as the primary
key. I have an Abort button to delete the current record and close the
form. If AutoNumber is assigned, the code executes a SQL statement
that deletes the current record. I need to be able to detect when
AutoNumber is unassigned (a new blank record) so that I can simply
close the form without running the SQL delete statement.

Unfortunately, no tests I can think of can identify when the AutoNumber
field is blank or NULL. Any ideas?

Oct 6 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<gt*******@gmail.comwrote
I'm having a problem with a form that uses AutoNumber as the primary
key. I have an Abort button to delete the current record and close the
form. If AutoNumber is assigned, the code executes a SQL statement
that deletes the current record. I need to be able to detect when
AutoNumber is unassigned (a new blank record) so that I can simply
close the form without running the SQL delete statement.

Unfortunately, no tests I can think of can identify when the AutoNumber
field is blank or NULL. Any ideas?
Fortunately, you explained _why_ you wanted to determine a Null AutoNumber.
In fact, if you have begun to enter any data in the Record, a number will be
displayed in a Control bound to Autonumber, even though the Record has not
been written.

But, you can accomplish your purpose with the test:

If Me.NewRecord = True Then

Be sure to put code in the BeforeUpdate event to accomplish the
cancellation, because (unless you have other required Fields) closing the
Form will write the dirtied Record.

Caution: Once displayed, that value for the AutoNumber is "used", so
cancelling the Record will not make it available for re-use and avoid the
"gap" in AutoNumbers of a cancelled Record, if that was another purpose of
what you wanted to do.

Larry Linson
Microsoft Access MVP
Oct 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.