473,385 Members | 1,872 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,385 software developers and data experts.

Command button to validate data

Hi,

I'm new to access. I have built a database and a form (along with a subform). Before the command button updates I want it to run a validation. The current VBA code for the button is:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Command20_Click()
  5. On Error GoTo Err_Command20_Click
  6.  
  7.  
  8.     DoCmd.GoToRecord , , acNewRec
  9.  
  10. Exit_Command20_Click:
  11.     Exit Sub
  12.  
  13. Err_Command20_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_Command20_Click
  16.  
  17. End Sub
I'm looking to add the following code in some manner:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.     If Me.[Cartons]-Me.[CartonCountSubtotal] <> 0 Then
  4.         MsgBox "Check your carton count!"
  5.         Cancel = True
  6.     End If
  7.  
  8. End Sub
I'm trying all kinds of different combinations and it just does not want to work. I only want the form to update if Cartons - CartonCountSubtotal = 0. Any thoughts?

Thank you in advance. This is driving me nuts.

Eddie.
Feb 7 '07 #1
7 4346
nico5038
3,080 Expert 2GB
Better to use a [Cancel] and [Save] button.
In the [Cancel] button code:

If Me.Dirty then
me.undo
endif
docmd.close

In the [Save button code:

If Me.[Cartons]-Me.[CartonCountSubtotal] <> 0 Then
MsgBox "Check your carton count!"
else
docmd.close
End If


Nic;o)
Feb 7 '07 #2
Better to use a [Cancel] and [Save] button.
In the [Cancel] button code:

If Me.Dirty then
me.undo
endif
docmd.close

In the [Save button code:

If Me.[Cartons]-Me.[CartonCountSubtotal] <> 0 Then
MsgBox "Check your carton count!"
else
docmd.close
End If


Nic;o)

Thank you so much for you quick reply. I'll kick it around and see if I can get it to work.

Eddie.
Feb 7 '07 #3
Thank you so much for you quick reply. I'll kick it around and see if I can get it to work.

Eddie.

Stupid question no doubt but is the Canel and Save button the same button? Or are there two? I can't find the save function in teh command button.

Eddie.
Feb 7 '07 #4
nico5038
3,080 Expert 2GB
It wil be two separate selfplaced buttons.
I use them always as it's the general way Windows forms work :-)

Nic;o)
Feb 7 '07 #5
missinglinq
3,532 Expert 2GB
Are the controls you're referring to, [Cartons] and [CartonCountSubtotal] both on the same form, or is one on the form and one on the subform?
Feb 8 '07 #6
Are the controls you're referring to, [Cartons] and [CartonCountSubtotal] both on the same form, or is one on the form and one on the subform?

One is in a form and the other in subform. Cartons is on the form and CartonCountSubtotal is in the in subform.
Feb 8 '07 #7
NeoPa
32,556 Expert Mod 16PB
Look in Referring to Items on a Sub-Form for ways to access CartonCountSubtotal on the subform.
The Me! version should work best for you.
Feb 9 '07 #8

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

Similar topics

3
by: Lo?c Mah? | last post by:
Hello I try to use a Validator for a TxtCtrl placed in a Panel with a Button in order to trigger the Validator and test the content of TxtCtrl. I have looked into wxPython documentation and...
18
by: Brad Pears | last post by:
Can someone give me some sample code on how one would go about executing a command line "command" from within an ASP form? We need to run an application called GnuPG which allows us to encrypt an...
2
by: Matt | last post by:
In the following code, I have 2 questions regarding submit button with image. 1) Does this code <input type="image" name="populate" src="populate.gif"> behave the same as an HTML submit button...
2
by: Humberto Alvarez | last post by:
Hi All I'm using asp requiredfieldvalidator and regularexpressionvalidator to validate a text field and a file input field respectively. The validation messages (the text property of the...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
2
by: moi | last post by:
Hello, I have a formview with a dropdownlist,a textbox and a button to add a new row with this fields. Everything works good (i have my new record) when i click on the button but how to be faster...
14
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.