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

Add New Record Help

P: 3
I'm sure this is a simple issue, I just can't seem to find what I am looking for -

I have an add new record button on my form. I want the user to input the data, but before it is actually added into the database, I want the user to confirm the information or cancel the add. How can I do this ? If I use acNewRec as soon as the user types in the first field the record is created...

THANKS for the help -
Jennifer
Aug 7 '07 #1
Share this Question
Share on Google+
3 Replies


missinglinq
Expert 2.5K+
P: 3,532
Assuming you're using a bound form (one tied to an underlying table/query) it doesn't matter how you get to your new record, whether using acNewRec or clicking on New Record button on Records Navigation, as soon as you enter one character in any control you have a new record! What you need to do, before saving the record, is ask the user if they want to save it. If not, you dump it using Me.Undo.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  If Me.NewRecord Then
  3.    If MsgBox("Would You Like To Save This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
  4.    Me.Undo
  5. Else 'Do nothing and record is saved
  6. End If
  7. End If
  8. End Sub
Now, befoe the record is saved, the user will be asked if they want to save it or not. As set up, the code has the messagebox default to the "Yes" button; to make it default to "No" simply replace vbDefaultButton1 with vbDefaultButton2.

If you want to ask the user if they want to save a new record or an old record that has been edited, take out lines # 2 an 7 and adjust the messagebox text accordingly. Make sure that Line # 3 is all on one line in your code.

Welcome to TheScripts!

Linq ;0)>
Aug 7 '07 #2

P: 3
Thanks ! It works great !
Aug 7 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
Glad we could help! You might glance at my original post again; just added a line or two in explanation, and not sure if it was just before your last post or just after it!

Linq ;0)>
Aug 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.