Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cancelling AddNew entry.

Posted on 1998-01-03
6
Medium Priority
?
204 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
[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
  • 5
6 Comments
 
LVL 8

Accepted Solution

by:
mrmick earned 150 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 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