Search the web
Sign In
New User? Sign Up
ms_access · Help and advice for users of MS access
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Need help getting a SUM   Message List  
Reply | Forward Message #21679 of 21712 |
Re: Need help getting a SUM

Pablo;

Here's what I would do:

1. Create a query with your table as the record source.

2. Drag the A field down to the Query Design Grid and drop it on the first
column.

3. In the first ROW of the second column type Fixer: 0

4. In the Criteria field of the first column (where you dropped the A field),
type Is Null

5. View the query.

6. Click on the gray column header bar of the Fixer column and then copy that
field using your preferred copy method. (Myself, I like to do the <Ctrl> <C>
keyboard combo.)

7. Click on the gray column header bar of the A column and paste the copied
information into that column. What you've just done is to replace all of your
empty fields with zeroes.

8. Return to the query design view.

9. Replace the A field with the B field. You can do this by doing one of the
following:

a. Drag and drop the B field into the Query Design Grid;

b. Click the drop-down list arrow just to the right of the A and select B;

c. Highlight the A field name and type in the B field name.

10. Make sure your criteria is still set to Is Null (in the B field column).

11. View the query again and do the copy/paste routine again to replace all
empty fields with zeroes.

Your "sum" procedure should work correctly now. As a side note, you might
consider setting the default value of the A and B fields to 0. You can do this
in the table design window of the table that contains these fields. Setting the
default value will automatically enter a zero in these fields with each new
record entered. Then as you enter new records, you can change the zero or leave
it be.

John A. Carter




--- In ms_access@yahoogroups.com, P S <discworld2004@...> wrote:
>
> Hello all,
>
> I need some help generating a sum of 2 fields, where at least one field is in
blank. I've attached a very small database that shows what I'm trying to do. I
have 8 rows, and 4 columns. ID, A, B, SUM.
>
> SUM = A + B.
>
> However, when A is blank or B is blank, I'm getting a blank value for SUM. I
would like to recode "blank As" and "blank Bs" to zero, so that I can get always
get a value for SUM. I have 1,000 rows, so I don't want to enter this data
again.
>
> Here is my code:
>
> Private Sub B_LostFocus()
> SUM = A + B
> End Sub
>
> Does anyone know how to recode A and B to make sure that I am getting a SUM
for every row?
>
> Thanks,
> Pablo
>
>
>
>
> [Non-text portions of this message have been removed]
>





Tue Jul 7, 2009 4:56 pm

winstar58
Offline Offline
Send Email Send Email

Forward
Message #21679 of 21712 |
Expand Messages Author Sort by Date

Hello all, I need some help generating a sum of 2 fields, where at least one field is in blank. I've attached a very small database that shows what I'm trying...
P S
psanchez95
Offline Send Email
Jun 13, 2009
5:14 pm

Use the Nz function. This will replace any Nulls with a zero. Private Sub B_LostFocus( )      SUM = Nz(A,0) + Nz(B,0) End Sub ...
Lonnie Johnson
prodevmg
Offline Send Email
Jun 15, 2009
12:17 am

Hi Pablo, Try This: Sum = nz([A]) + nz([B]) Hope this will help.... jre...
jre.phils
Offline Send Email
Jun 15, 2009
3:44 am

Thank you....
psanchez95
Offline Send Email
Jun 16, 2009
4:58 am

Hello Roy, This is all I needed and it worked: If isnull(A) then SUM = B If isnull(B) then SUM = A If not isnull(A) and A <> "" and not isnull(B) and B <>...
P S
psanchez95
Offline Send Email
Jun 16, 2009
3:13 am

Pablo; Here's what I would do: 1. Create a query with your table as the record source. 2. Drag the A field down to the Query Design Grid and drop it on the...
winstar58
Offline Send Email
Jul 7, 2009
4:56 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help