Solved

Me.undo only wipes out user entered data in new record.

Posted on 2015-02-15
4
147 Views
Last Modified: 2016-02-11
Microsoft Access 2013 - Form question

Hi

I am using the Form_BeforeInsert event to populate some fields when the user enters a new record.

 When entering a new record, one of the fields that the user must enter in is [StockNumber].     The idea is to cancel record entry if the stocknumber does not exist in a lookup table.   I have used
me.undo

Open in new window

to cancel the record, but this will only wipes out the data that the user has typed in.  The fields that were populated in the Form_BeforeInsert event remain.

Pressing the escape key does the trick.

I suppose I could  try programmatically nulling out those fields, but this does not seem very elegant.    I presume that there is a better way.

I would like programmatically  cancel the new record.

Thank you.
0
Comment
Question by:peispud
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40610839
use the beforeUpdate  event of   [StockNumber] to check for duplicates

private sub me.StockNumber_beforeupdate(cancel as integer)

'if duplicate
     cancel=true
     exit sub


end sub
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40610856
You can also use Cancel = True in your BeforeInsert procedure.

Ron
0
 

Author Closing Comment

by:peispud
ID: 40610863
The solution was to move the code to the BeforeUpdate event.

Thank you for your help.
0
 
LVL 75
ID: 40611176
You should use the BeforeInsert event with the Cancel option, as noted. That is exactly the intent of that event.  No point in have the user enter a bunch of data, only to find out later (in the BU event) that the Stock Number does not exist.

mx
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now