Cacel new record?

geralf

Registered User.
Local time
Today, 03:23
Joined
Nov 15, 2002
Messages
212
Cancel new record?

I have function that find the last record, looks at the primary key field value and adds 1 to the number. My records get this sequence 1001, 1002, 1003, 1004......... and so on. The user must clicks a button to add a new record. The user is then prompted with a question if he or she wants to add a new record.

Now if the user clicks 'No', then I'd like the user to bee at the same record as when the 'Add Record' button was clicked.

The problem now is that the record gets canceled (using the BeforeInsert event) but there's now a 'new' record containing default values. Now for instance the record navigation bar displays 'record 7 of 7'. If I now click on the 'previous button' on the navigation bar - it now displays 'record 6 of 6'. I would like to be at this place automatically after pressing 'No' to add records.

I've tried using DoCmd.GoToRecord commands without any luck.

Any suggestions?

Thanks in advance
 
Last edited:
Hi Rich

No, it did not. I did not know of the Undo method, so thanks for bringing that to my attention.

In short summary the problem comes down to this: On canceling the insertion of a new record in the BeforeInsertion event - the new record is there on the screen. I manually have to move to a previous record. Then the 'new record' disappears - which should not have been there in the first place. Other suggestions or info on cancelling a 'new record?
 
This seems to work
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim Msg, Style, Title, Response, MyString

If RecordsetClone.RecordCount > 0 Then


Beep
Msg = "Do you wish to add a new record ?"
Style = vbYesNo + vbExclamation + vbDefaultButton1
Title = "Confirm new record"
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then
DoCmd.GoToRecord , , acPrevious



End If
End If
End Sub
 
Last edited:
Hi Rich

I've tested it on my db, and it still don't work, so I tried it on a simple testdb, and then it works (you have probably forgotten the Cancel=True after the DoCmd line). I have to search in my current event for the form, since there's a lot going on there with sql and function calls etc. I now know at least how to use the BeforInsert event.

If this is hard to resolve I have the possibillity to ask the user to confirm the new record in a custom 'Add new record', before adding the new 'default record'. I then have to switch off the navigational buttons which include the built in 'Add new Record'
or perhaps it's possible to unteract with the code of that button?

Thanks very much for the help Rich

Gerhard
 

Users who are viewing this thread

Back
Top Bottom