Solved

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

Posted on 2015-02-15
4
156 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
[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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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 …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

738 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