473,499 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

On new record, abandon record before it is saved?

Seth Schrock
2,965 Recognized Expert Specialist
I've got a way for the user to delete the record. The user just didn't know it. I might end up putting a Delete button next to the Undo button so that they can find it easier.

An idea just occurred to me. If a user starts typing a new record and decides they don't want a new record, is it possible to delete the record before it is saved? If so, then I could just replace my Undo button with a Delete button that will work as both my Undo and Delete button. I know the functions are totally different, but in this case, the Undo wasn't to undo changes to an existing record, but to stop the creation of a new record if the user found out that the order had already been inputted.
Jan 2 '13 #1
3 7734
zmbd
5,501 Recognized Expert Moderator Expert
New question new thread.
I hope the title works. :)

User can hit [Esc] key.
In either before_insert or before_update event of the form the set cancel = true : me.undo - I have a form that does just that in the before insert event. The only issue is that the autonumber field increments even though the user canceled the record save.

I know I'm missing something here; however, I'm just a tad scattered today with the Holidays and current family events

Anyway here's one I use in the before insert:

IF the answer is [No] the new record isn't inserted and the autonumber doesn't increment either.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2. Dim zvbyesno As Long
  3. '
  4.     zvbyesno = fnc_msg_confirm_action_defaultNo("This is a real time change! Before Insert..." & vbCrLf & "This can not be undone once confirmed!")
  5.     If zvbyesno = vbNo Then
  6.         Cancel = True
  7.         Call sub_msg_action_canceled
  8.         Me.Undo
  9.     End If
  10. End Sub
I use basically the same code in the before_update, if the answer is [No] then the record is aborted; however, the autonumber in the table is incremented.

(line 4, I have a series of the same message boxes some with yes/no or yes/no/cancel, different default buttons icons, one day I put them all in a standard module as functions or subs if I didn't need a return, and then I just pass the header message text)
Jan 2 '13 #2
NeoPa
32,557 Recognized Expert Moderator MVP
Forms have two properties that might prove helpful with this logic Seth - .NewRecord and .Dirty.

.NewRecord tells the code that the buffer is currently loaded with data for a new record, and .Dirty tells the code that changes have been made to data in the buffer.

No deletes need (or even can) be performed on a record until it has been saved the first time at least, as it isn't stored in the table until that point.

With this information you can use code triggered by a button.
Jan 2 '13 #3
Seth Schrock
2,965 Recognized Expert Specialist
Okay. Sorry I wasn't able to get back sooner. I got pulled away to another task.

I really don't care about the autonumber being incremented, so I'll just stick with the simple method and keep what I've got in the Undo button and just add a delete button.

Thanks Z and NeoPa for your help.
Jan 3 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2604
by: Andrew | last post by:
Hi All, Have come across something weird and am after some help. Say i run this query where rec_id is a column of table arlhrl, select * from arlhrl where rec_id >= 14260 This returns to...
1
1735
by: Robin S. | last post by:
More clueless newbie questions... Table 1: "available specs" Table 2: "classes" A single form shows a single record from the table "classes". Each record in "classes" may contain several...
5
1513
by: MLH | last post by:
Anyone remember how to determine a particular record's record number (Access 2.0 table question)?
15
11227
by: Susan Bricker | last post by:
Greetings. I have a Mainform with a subform. The Mainform has single record format and subform has continuous form format. When the Mainform opens, I force allowadditions and allowedits to FALSE...
1
2150
by: sal21 sal21 | last post by:
I use this code to update a sql database from excel to sql... Now i would want to arange this code to export an Access table into sql databse... Sub ADOExcelToSQLServer() Dim Cn As...
0
1182
by: ian | last post by:
One of my customers occasionally gets a corrupted record - where all the fields show #error and forms bound to the damaged table do not open (the VBA code doesn't execute) and the error message is...
1
1185
by: John | last post by:
Hi I need to run a query when a new record is inserted and another one when a record is modified. What events do I need to trap? Thanks Regards
1
4779
by: alex.gruenther | last post by:
I am new to Access and need help creating an edit record form. I've got a table called Player with attributes like name, address, phone, etc. I've created an edit player form with a combo box...
4
1783
ollyb303
by: ollyb303 | last post by:
Hi, I have a problem I need some help with. In my Access 2000 database (used for logging complaints to my company), I'm using the following code to send an email to our finance dept when a...
13
11785
by: stateemk | last post by:
I have a form that will have about 50 - 100 records entered at a time all needing the same batch number. All the other data will need to change, but I would like to be able to retain that batch...
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5467
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.