?
Solved

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

Posted on 2014-11-12
3
Medium Priority
?
140 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 2000 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 51

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

770 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