Solved

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

624 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