Solved

Adding FldA with FldB to equal in FldC

Posted on 2014-12-12
16
122 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 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 35

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 35

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 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 35

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 35

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 35

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

831 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