You can use your favorite social network to register or link an existing account:
Or use your email address to register without a social network:
Sign in with these social networks:
Or enter your username and password
Forgot your password?
Yes, please link my existing account with for quick, secure access.
No, I would like to create a new account with my profile information.
When you are in the process of entering a new record in an Access database, you can press the Escape key to cancel the entry of the record. However, some events, such as clicking or tabbing into a subform on the main form, can save the record on the main form. At that point, you can't press Escape to cancel the entry—you must use the Delete command to delete it. The end-users of your database might not understand the difference, and would probably want a single button or keyboard shortcut that just gets rid of the record, regardless of whether it’s been saved or not. To do this, you need to be able to which of these two states the record is in:
a) The record is being built up, has been assigned an AutoNumber ID, but hasn't been committed to the table yet - OR - b) The record has already been committed and the ID indicated is already persistent.
The solution is to add a module-level variable (mboolIsInsert ) to the parent form. The variable is set to True in the BeforeInsert event on the form, and reset to False on the OnCurrent event. The OnCurrent event doesn’t fire for the parent form when you click or tab into the subform, only when you directly navigate on the main form. You can then check the value of the module-level variable in your code to see if you’re in an insert event and respond as appropriate.
Option Compare Database Option Explicit Private mboolIsInsert As Boolean Private Sub Form_BeforeInsert(Cancel As Integer) mboolIsInsert = True End Sub Private Sub Form_Current() mboolIsInsert = False End Sub Public Sub CancelOrDeleteRecord() If mboolIsInsert Then 'Add code to perform escape-equivalent cancel Else 'Add Delete command to delete the current record End If End Sub
Running the CancelOrDeleteRecord() procedure (for example, from a button on the main form) provides a more usable form by always getting rid of the record, regardless of whether it's been saved or not.
Thanks to Access PM Russell Sinclair for the tip!
Comments: (8) Collapse
Thanks for the power tip, is simple and useful.
In a multiuser database, as soon the main record is saved it shows in other users list. We cand put the boolean IsInsert as a column in the main form table. This way it's possible to filter out records (IsInsert = False)that aren't Explicitly saved by the user.
Useful tip that does not require a great deal of code to implement.
Thanks
The search-box searches ALL MSDN blogs?
http://google.com
good post!
Good tip! Another option is to use an unbound form and append the record only when the "Save" button is clicked. See my blog post for details: blog.msvba.com/.../using-unbound-forms-part-1-saving.html
@Laura: Great alternate approach! Thanks for posting.
Thanks, great tip! Another approach - use form's Dirty property instead of mboolIsInsert variable: Public Sub CancelOrDeleteRecord() If Me.Dirty Then 'Add code to perform escape-equivalent cancel Else 'Add Delete command to delete the current record End If
End Sub
Comments: (loading) Collapse