Solved

Adding FldA with FldB to equal in FldC

Posted on 2014-12-12
16
120 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
  • 6
  • 5
  • 3
  • +1
16 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40496745
is your form bound?

you can set the control source of FldD to

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

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 49

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
 
LVL 34

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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
ID: 40497019
your fields must be Number not TEXT
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 49

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 34

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 34

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 34

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now