Solved

Don't save a record if nothing changed (have pre-filled data from another form)?

Posted on 2014-11-12
3
138 Views
Last Modified: 2015-01-19
I have a form with a button to add new activity to the current record. In my activity form, I have a field that gets it's case ID from the open form. If a user closes the form, it creates a new record because that field was technically "filled out" with the ID. How do I tell it to not create a new record if nothing changed or was entered?

Thanks!
0
Comment
Question by:Kevin Smith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40437829
Test for it in the Form_BeforeUpdate:

Private Sub Form_BeforeUpdate(Cancel As Integer) 
   If <<ConditionsForNotSaving>> then
        Me.Undo 
  End If
End Sub

Open in new window

0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40437830
Don't set the value of the ID. Instead, assign the number as the DefaultValue of the ID. This way, no data are added before the user starts writing.

/gustav
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 40438021
Never, ever dirty a record yourself with code.  If you need to populate foreign keys or data fields, do it in the form's BeforeInsert event.  That way your code will only run for new records and it will only run after the user has dirtied the record.  That prevents "empty" records from being created or the user from getting error messages he doesn't understand because he "knows" that he didn't change anything.

Or you can use the form's Dirty event but in that case, you MUST check to determine if it is a new record because you don't want to overlay existing data.
If Me.NewRecord = True Then
    populate the fields
End If
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question