Hi everyone!!
I have a problem. I have a form for entering new data. If the user clicks the button on my frmMain (cmdAdd), the form for entering new data appears. However, IF the user decides NOT to enter any data and click the cancel button instead of the Save button and error pops up. How do I keep this from happening? I've implemented some error checking but still no results. Here's my code... - Private Sub cmdCancel_Click()
-
On Error GoTo errHandle
-
Dim intProcced As Integer
-
-
'Warn the user that any information entered will be lost, then if the user responds that it is
-
'ok, erase the record and close the form
-
-
intProcced = MsgBox("Warning: Any changes made or any information entered will not be saved.", vbOKCancel, "Warning")
-
If intProcced = 2 Then
-
Exit Sub
-
End If
-
-
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer1X
-
-
DoCmd.Close
-
-
Exit Sub
-
-
errHandle:
-
If Err.Number = 2046 Then
-
DoCmd.Close
-
Exit Sub
-
Else
-
'Print the error message and send an email to Administrator
-
SendErrorMsg "cmdCancel_Click on frmEnterNewFeeder", Err.Number, Err.Description
-
MsgBox Err.Description
-
End If
-
Exit Sub
-
-
End Sub
Thanks for any and all help!!!
2 2411
... - DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer1X
-
...
Hi. When no change has been made there is nothing to undo, and executing the Docmd causes an error.
You can test specifically whether or not a change has been made to the underlying record using the form's Dirty property. You can also substitute the form's Undo method for the menu command you have used. The revised undo code is then just - If Me.Dirty then
-
Me.undo
-
Endif
-Stewart
Hi. When no change has been made there is nothing to undo, and executing the Docmd causes an error.
You can test specifically whether or not a change has been made to the underlying record using the form's Dirty property. You can also substitute the form's Undo method for the menu command you have used. The revised undo code is then just - If Me.Dirty then
-
Me.undo
-
Endif
-Stewart
Hey thanks! That worked great!
-Joseph
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Corepaul |
last post by:
I am working in Windows 2000 and Access 2000 and am a rookie in Access.
Coding merrily along, I stop periodically to test that everything works.
After adding a small amount of code to several events, when I try to run the
form suddenly won't run. I get the message "The expression On Open you entered
as the event property setting produced the following error: Constant Expression
Required."
Two possible reasons follow on the screen:
|
by: Deano |
last post by:
Alot of my forms are bound.
I would like to offer a Cancel option so that they can make as many changes
as they like and still Cancel out without making any changes.
I have one idea of how to do this for new records; tag each record with a
boolean value. On clicking OK, these are all set to True and the form
closes.
If they Cancel the False records are deleted and the form closes.
|
by: Charles Law |
last post by:
Under what circumstances would e.Cancel be set to True on entry to the
Closing event of an MDI child form?
I have found that this is why my application won't close properly. I can
explicitly set the value to False, but I would have expected it to be False
on entry.
TIA
Charles
|
by: martin |
last post by:
Hello,
Is there a way to make a kind of "cancel" button on a form?
Suppose you accidently changed or overwrote some data in a form, then I'd
like to leave this form at once and cancel any change made in this form.
Hopefully someone has a clue for me.
thanks a lot!
|
by: bg_ie |
last post by:
Hi,
I have an event handler to handle the closing of a form. In this
handler (Form1_FormClosing), I ask the user if they wish to save
updates made to a file. I wish to add the option to the message box to
allow the user to cancel so that the form doesn't actually close. This
is the behaviour you would see if you closed a word document - Save
changes to X.doc - Yes,No,Cancel.
Thanks for your help,
| |
by: Matuag |
last post by:
Hi All,
I want to create following command buttons on a Form which users can
edit.
Save ( Save Changes made)
Cancel ( Undo data changes)
Exit ( Close form)
I am using Macros for each of these commands and they work perfect.
|
by: gregerly |
last post by:
I'm working on a corporate intranet site and am trying to create a page that will warn a user on window unload if they have not saved thier work. Basically I just select all inputs, and on change, set var changes = true; On window unload if changes==true, they have made changes that are not yet saved, and I want a confirm box to pop up, asking if they really want to leave or stay on the page? At this point is it to late to cancel the window...
|
by: jmarcrum |
last post by:
Hello all,
i have a continuous form that displays about 1000 records and opens when I click a button. When the form opens, the user has the option of checking a checkbox that is located beside each record. The checkbox is labeled "Move" (for moving multiple records at a time to another year). Of course, the checkbox is set as a control "moveRecord" on a table that the query is pulling from. So if the user checks one record, then clicks to...
|
by: jmarcrum |
last post by:
Hey everybody!
I've created 2 buttons that I've placed on all my forms: a Save button & a Cancel button.
The cancel button I have a question about.
I used the wizard to create the button and I selected the Record Operations/Undo Record option. I edited the vba code to have the button also close the form after it undoes any changes. Here is the actual code for the OnClick event for the cancel button:
Private Sub cmdCancel_Click()...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |