Solved

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

Posted on 2015-02-15
4
142 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 119

Accepted Solution

by:
Rey Obrero 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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 …

744 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

14 Experts available now in Live!

Get 1:1 Help Now