A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to validate sum of fields (access 2003)



 
 
Thread Tools Display Modes
  #1  
Old April 23rd, 2010, 12:03 PM posted to microsoft.public.access.forms
Paula
external usenet poster
 
Posts: 278
Default How to validate sum of fields (access 2003)

Hi,

I'm running a query in order to find records that have at least one match,
based on a form - where I select a certain record - and a subform - where the
matching records are displayed. The search is based on four parameters
(located in the main form), which are scored from 0 to 1 (passing through
0,25, 0,5 and 0,75). The results that appear in the subform are ranked and
filtered according to the sum of those four criteria and corresponding scores.

Now, my problem is very simple but so far I haven't found a solution that
works: I want to validate the sum of those four criteria scores so that it
doesn't exceed the maximum possible score (=1); in case this condition isn't
met, the query shouldn't be updated.

I've tried putting this piece of code in the (main/sub) form's properties
(namely, in the before/after update event) but it isn't working:

If Score1 + Score2 + Score3 + Score4 1 Then
MsgBox "Verify sum"
Cancel = True
Me.Undo
End If

Thanks in advance,

Paula
  #2  
Old April 23rd, 2010, 12:15 PM posted to microsoft.public.access.forms
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default How to validate sum of fields (access 2003)

Your code allows only for the result being exactly 1. Less or more than 1
generates the error message. The expression should be, as I understand the
situation:

If Score1 + Score2 + Score3 + Score4 = 1 Then
etc.

The validation code needs to be in the form's Before Update event. After
Update runs after the values have been written to the table. They are two
different events.

By using Me.Undo you are wiping out the entire record and forcing the user to
start over from the beginning. Don't you want to allow the user to go back
and fix the data in the Score fields?

Paula wrote:
Hi,

I'm running a query in order to find records that have at least one match,
based on a form - where I select a certain record - and a subform - where the
matching records are displayed. The search is based on four parameters
(located in the main form), which are scored from 0 to 1 (passing through
0,25, 0,5 and 0,75). The results that appear in the subform are ranked and
filtered according to the sum of those four criteria and corresponding scores.

Now, my problem is very simple but so far I haven't found a solution that
works: I want to validate the sum of those four criteria scores so that it
doesn't exceed the maximum possible score (=1); in case this condition isn't
met, the query shouldn't be updated.

I've tried putting this piece of code in the (main/sub) form's properties
(namely, in the before/after update event) but it isn't working:

If Score1 + Score2 + Score3 + Score4 1 Then
MsgBox "Verify sum"
Cancel = True
Me.Undo
End If

Thanks in advance,

Paula


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201004/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:06 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.