?
Solved

Adding FldA with FldB to equal in FldC

Posted on 2014-12-12
16
Medium Priority
?
135 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 38

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 51

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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 38

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 51

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 38

Accepted Solution

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

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 38

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 38

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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