Solved

Cancelling AddNew entry.

Posted on 1998-01-03
6
196 Views
Last Modified: 2006-11-17
During an AddNew procedure, how can I allow the user to cancel what he has typed so it does not get written to the database?  I am using VB4/32.

Thanks,
Don
0
Comment
Question by:deross
  • 5
6 Comments
 
LVL 8

Accepted Solution

by:
mrmick earned 50 total points
ID: 1449047
If you do not invoke the .UpDate method, it will be canceled.  Once you perform and .Update, you'll have to just delete the record.
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1449048
By the way, this is also true of the .Edit method, if you don't invoke the .Update method, changes are discarded.
0
 

Author Comment

by:deross
ID: 1449049
But if I move to another record using the data control or even if I close the form that my AddNew procedure is on, the record still gets added.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:mrmick
ID: 1449050
Whoops, Until you use the update method, no changes are made, but the record is still added.

To delete the most recently added record use the following (assumes rs = your recordset):

   rs.bookmark = rs.Bookmark = rs.LastModified
   rs.delete

Note: Always keep a backup the database until you're sure your code is working properly when coding any type of delete.

0
 
LVL 8

Expert Comment

by:mrmick
ID: 1449051
Make sure your procedure only executes the above code if a record was added and the user decided to cancel.
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1449052
A possible method of insuring the added record is used or deleted would be to create a module level variant variable called AddedUnused.   Assign the bookmark of the newly added record to AddedUnused.  Then call a separate procedure that looks like this to cancel:

Sub CheckUnused()
Dim rs As Recordset
 If Not IsEmpty(AddedUnused) Then
  rs.Bookmark = AddedUnused
  rs.Delete
  AddedUnused = Empty
 End If
End Sub

If you choose to use the above sample, make sure you set AddedUnused = YourBookMark directly after you invoke the AddNew method... AND directly after you invoke the .Update method, set AddedUnused = Empty.  In the form unload event, you could call CheckUnused() allowing your user to close the form as another means of canceling the edit OR you could make sure AddedUnused = Empty in the Form_QueryUnload event to decide if you would permit your user to close the form without first canceling.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 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