adding blank record on close

jojo

Registered User.
Local time
Today, 17:55
Joined
Jul 20, 2012
Messages
51
I have menu form with a button to open the data entry form to a new, blank record. The record displays with the fields blank, but with the defaults filled in, and with the autonumber incremented. If the user then decides not to do any work, but closes by clicking the X that new record is saved in the table with all the other fields blank. I put code into Form Unload event to check if a field is blank, and if so, delete this record, but I still get a blank, and looking at the table, the NEXT autonoumber is the last record! I have a command button to return to the main menu that works, but I have no control over which method she'll use. Access 2010
thank you so much
jojo
 
1. If you have defaults that fill in automatically so that the autonumber appears then that autonumber will be lost.
2. If you have a record that has started a record, you should be able to use the form's BEFORE UPDATE event to cancel the update and undo the record (the autonumber will still be used up) before the form closes.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
   ' put code here to check to see if the controls all have data.
   ' if they don't then issue a
  Cancel = True
  Me.Undo
End Sub
 
Thank you very much, Bob Larson! I struggled with that for days. Works now. But if I open, close, then reopen (using the button that opens the form to a new blank rec exc for defaults), i don;t understand why it actually skips 2 numbers the next time I reopen. (It's ok that the numbers skip a lot, as it will not usually happen in the real world, and at least we're not saving a rec with all blank fields exc for the defaults)...just curious!
Thnank u so very much for that quick on target reply...it's just great!
 
Thank you very much, Bob Larson! I struggled with that for days. Works now. But if I open, close, then reopen (using the button that opens the form to a new blank rec exc for defaults), i don;t understand why it actually skips 2 numbers the next time I reopen. (It's ok that the numbers skip a lot, as it will not usually happen in the real world, and at least we're not saving a rec with all blank fields exc for the defaults)...just curious!
Thnank u so very much for that quick on target reply...it's just great!
Skipping two numbers? Do you mean if the one prior to the record that was almost saved but backed out was 200 that the next actual record was 2003? If it is 202 then it would be correct.

So, if I save a record with an autonumber of 200 and then I start a new record the autonumber will show 201. If I undo that record, that autonumber is gone forever as well, and the next record I go to enter should be 202.
 
Thanks so much for that explanation adn your earlier answer. This forum is so amazing, helpful! It took me till now to reply bec yesterday i tested so many times, i neededa break, and i put your before_update code in, so I had to go back to an older version, and test out the numbers. I put in a message box, right after the delete so that when I click X it stops, and the id number goes from 200 to (new). Then when I go back to the table, the last rec (which is a blank that I don't want in the NEXT number! I guess that makes sense.
Now, here's something weird. I wondered why i put code into Unload, and it was working (not saving a blank), then it started adding the blank again. I noticed that the older version was opening the form with id =(new). Then when it stopped working it was loading w/ an actual id number, so of course that's why I was finding a blank! The macro that calls the form didn't change-a very simple embedded macro that opens the form with gotorecord New. Why the change? any ideas
Thanks a again. have a great weekend.
 

Users who are viewing this thread

Back
Top Bottom