Solved

Cancelling AddNew entry.

Posted on 1998-01-03
6
192 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 8

Expert Comment

by:mrmick
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now