Solved

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

Posted on 2014-11-12
3
136 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 36

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA 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 …

726 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