Improve company productivity with a Business Account.Sign Up

x
Solved

# Adding FldA with FldB to equal in FldC

Posted on 2014-12-12
Medium Priority
143 Views
Last Modified: 2014-12-12
So I have to where FldA + FldB + FldC = FldD....But I don't want it to show in FldD until I have enter a number in FldB or FldC...FldA already has a number in it.

So this is the way it looks now..

FldA + FldB + FldC = FldD
12   + BLANKB + BLANKC = 12

The BLANKB and BLANKC is where I will have the user input a number....But I don't want the total to show unless the user does some input in the blank fields
0
Question by:Jass Saini
• 6
• 5
• 3
• +1
16 Comments

LVL 120

Expert Comment

ID: 40496745
is your form bound?

you can set the control source of FldD to

=([FldA]+[FldB]+[FldC])
0

LVL 41

Expert Comment

ID: 40496884
If you don't want the total to show until both variable fields are filled, you need to add code to several events.
``````If IsNull(Me.FldB) or IsNull(Me.FldC) Then
Else
Me.FldD = Me.FldA + Me.FldB + Me.FldC
End If
``````
This code needs to go into both the FldB AfterUpdate event and the FldC AfterUpdate event.  You may also want code in the Form's Before Update event to stop the update if either field is empty.
``````If IsNull(Me.FldB) or IsNull(Me.FldC) Then
Msgbox "Both FldB and FldC are required.",vbOKOnly
Me.FldB.SetFocus
Cancel = True
Exit Sub
Else
Me.FldD = Me.FldA + Me.FldB + Me.FldC
End If
``````
0

LVL 53

Expert Comment

ID: 40496974
Use this expression for fldD:

=Nz(FldA,0)+Nz(FldB,0)+Nz(FldC,0)

Then any field can be Null.

/gustav
0

LVL 41

Expert Comment

ID: 40496987
If you want to do this as an expression then,

= IIf(IsNull(FldB) OR IsNull(FldC), null, Nz(FldA,0)+Nz(FldB,0)+Nz(FldC,0))

But, you should probably still have code in the Form's BeforeUpdate event to ensure that B and C eventually get populated.
0

LVL 120

Expert Comment

ID: 40497002
why go to all those codes and nz(), this enough for the OP is asking

=([FldA]+[FldB]+[FldC])
0

Author Comment

ID: 40497008
Ok..Now I am confused...Should I code it and if I code what ControlSource (FldD) in the BeforeUpdate Event???

Also Gustav....I am currently doing that expression now...but field D is the same as field A and I have not enter anything into B or C, field A has something in it.
0

Author Comment

ID: 40497011
Rey ...I tried that to in was concatenating.. A+B+C = ABC...instead of D
0

LVL 120

Expert Comment

ID: 40497019
your fields must be Number not TEXT
0

LVL 53

Expert Comment

ID: 40497020
Sorry, missed that. Pat showed how:

=IIf(IsNull(FldB) Or IsNull(FldC),Null,FldA+Nz(FldB,0)+Nz(FldC,0))

/gustav
0

Author Comment

ID: 40497022
Pat what if I only need Fld B or Fld C....they don't have to both but the total goes into fld D...
0

Author Comment

ID: 40497027
Also how do I tie it back into my table for Fld D??
0

LVL 41

Accepted Solution

PatHartman earned 2000 total points
ID: 40497073
JA,
You are making this harder than it needs to be by suppressing the total until both fields are filled in.  Now you've changed the requirement to only needing 1 field.  You never responded to whether at least one of the fields is required so I can't tell you whether it is better to use the expression in the ControlSource or VBA.

To calculate if at least ONE of the values is present:
=IIf(Not IsNull(FldB) Or Not IsNull(FldC), FldA+Nz(FldB,0)+Nz(FldC,0), null)

I believe you've already been told that it is poor practice to store the calculated value and that is why no one has posted any code for it.  Why would you store it when you can include the expression in the query and ALWAYS be assured that you are working with the current value.  Once you store a calculated value, it becomes invalid as soon as someone updates one of its operands so your app MUST ensure that NEVER happens.  Best practice - calculate as you need it and the query is more convenient because you can reuse the query in other places.  If you go with an expression in the ControlSource, you have to repeat that expression EVERY place you need to see fldD.

The VBA I posted a while back would save the value if FldD were bound.  You cannot save the calculated value using either the query method or the ControlSource method.  The ONLY option is the expression in the Else part of the VBA.
0

Author Closing Comment

ID: 40497103
Thanks Pat...it's a lot info to take in..I am still learning and my boss did not give me any time to learn access.  I am just being thrown in.  That is why I am asking a lot of questions
0

LVL 41

Expert Comment

ID: 40497125
It is brave of you to try.  There are lots of videos and papers on the web that will help you learn faster.
0

Author Comment

ID: 40497143
I have tried UDemy...they teach the basic.  I am currently enrolled in an online class through the community college.  Please let me know what you think or come across something that is good
0

LVL 41

Expert Comment

ID: 40497194
Look for Access videos by Crystal.  She does a lot of basic stuff and she writes well also.
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Join & Write a Comment Already a member? Login.

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
###### Suggested Courses
Course of the Month10 days, 13 hours left to enroll

#### 607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.