Solved

Adding FldA with FldB to equal in FldC

Posted on 2014-12-12
16
124 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
Comment
Question by:Jass Saini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +1
16 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40496745
is your form bound?

you can set the control source of FldD to

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

Expert Comment

by:PatHartman
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

Open in new window

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

Open in new window

0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40496974
Use this expression for fldD:

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

Then any field can be Null.

/gustav
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 36

Expert Comment

by:PatHartman
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

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


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

Author Comment

by:Jass Saini
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

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

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40497019
your fields must be Number not TEXT
0
 
LVL 50

Expert Comment

by:Gustav Brock
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

by:Jass Saini
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

by:Jass Saini
ID: 40497027
Also how do I tie it back into my table for Fld D??
0
 
LVL 36

Accepted Solution

by:
PatHartman earned 500 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

by:Jass Saini
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 36

Expert Comment

by:PatHartman
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

by:Jass Saini
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 36

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

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

Join & Ask a Question