473,395 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Remove validation from save process

Belimisimus
Hello, everyone!

I add a "Yes" "No" "Cancel" option on the before update event of the form.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.             answer = MsgBox("Do you want to save changes?", vbYesNoCancel + vbQuestion, "Confirm Save")
  3.             If answer = vbNo Then
  4.                 Me.Undo
  5.             ElseIf answer = vbCancel Then
  6.                 Cancel = True
  7.             End If
  8. End Sub
Also have save button on top of the form.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2.     On Error Resume Next
  3.     DoCmd.RunCommand acCmdSaveRecord
  4. End Sub
Is there a way to skip msgbox from BeforeUpdate in case when I click Save button? Obviously, if I click save I want to save... there is no need to ask me validation.
Mar 16 '10 #1

✓ answered by TheSmileyCoder

Hi and Welcome to Bytes.

Please remember to use the [code][/code] tags provided around your code.

What I do, is to have a private variable bSaving declared in the forms module, at the top, outside any procedure.

The Form_BeforeUpdate should then look:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   If Not bSaving Then
  3.     answer = MsgBox("Do you want to save changes?", _
  4.                   vbYesNoCancel + vbQuestion, "Confirm Save")
  5.     If answer = vbNo Then
  6.       Me.Undo
  7.     ElseIf answer = vbCancel Then
  8.       Cancel = True
  9.     End If
  10.   End If
  11. End Sub
With the save button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2.   bSaving=True
  3.   On Error Resume Next
  4.   DoCmd.RunCommand acCmdSaveRecord
  5.   bSaving=False
  6. End Sub

3 2019
TheSmileyCoder
2,322 Expert Mod 2GB
Hi and Welcome to Bytes.

Please remember to use the [code][/code] tags provided around your code.

What I do, is to have a private variable bSaving declared in the forms module, at the top, outside any procedure.

The Form_BeforeUpdate should then look:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   If Not bSaving Then
  3.     answer = MsgBox("Do you want to save changes?", _
  4.                   vbYesNoCancel + vbQuestion, "Confirm Save")
  5.     If answer = vbNo Then
  6.       Me.Undo
  7.     ElseIf answer = vbCancel Then
  8.       Cancel = True
  9.     End If
  10.   End If
  11. End Sub
With the save button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2.   bSaving=True
  3.   On Error Resume Next
  4.   DoCmd.RunCommand acCmdSaveRecord
  5.   bSaving=False
  6. End Sub
Mar 16 '10 #2
Nice and clear... the problem is solved!
I'm newbie with VBA but this was very simple even for me!

Instead of private, I add public variable, because I have multiple forms with "save", "save and new" and "close" button and everything is working just fine!

Thx TheSmileyOne :)
Mar 16 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Thats good to hear :)
Mar 17 '10 #4

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

Similar topics

9
by: Nikol | last post by:
We all know that some users try to post strange data to our databases, so like many others I make validation with ereg() and regular expressions. But some users find it very annoying, if they have...
22
by: downview | last post by:
When I attempt to validate my style sheet using the w3c validator, it tells me that I need a correct document parse tree. The confusing thing is my page validates as XHTML Transitional 1.0. Does...
4
by: Craig G | last post by:
i have the following code for validating a textbox once a page posts, but the problem i am having is that the TextChanged event won't fire next time if the user does not change the value again ...
9
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see)...
2
by: Fourge | last post by:
Hi, I have run into a very strange scenario. In developing an ASP.NET application on framework version 1.1, I found that certain client-side validation scripts were not being rendered. The...
2
by: Tim Frawley | last post by:
Source code attached indicates my problem with validation and a button bar save button. Fill the Textbox with some text then tab off the control. The message box will display the text in the...
6
by: serge calderara | last post by:
Dear all, I have read that ASP.NET does double user input validation of control when they are place on the page. Once on teh client side and again from server side right ? Could explain how...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
1
by: John Chan | last post by:
Hi, Im doing a maintenance application in ajax and coldfusion at work on IE6 exclusively. I have a save button on each form and i have to do various validations server side and on client side...
6
by: lists | last post by:
Hi all, I am trying to validate an XML file against an XSD schema file within a ..NET C++ program, but the validation doesn't seem to be occuring. My code is listed below. The validation...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.