Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

735 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