Link to home
Start Free TrialLog in
Avatar of Jass Saini
Jass Saini

asked on

Adding FldA with FldB to equal in FldC

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
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

is your form bound?

you can set the control source of FldD to

=([FldA]+[FldB]+[FldC])
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

Use this expression for fldD:

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

Then any field can be Null.

/gustav
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.
why go to all those codes and nz(), this enough for the OP is asking


=([FldA]+[FldB]+[FldC])
Avatar of Jass Saini
Jass Saini

ASKER

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.
Rey ...I tried that to in was concatenating.. A+B+C = ABC...instead of D
your fields must be Number not TEXT
Sorry, missed that. Pat showed how:

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

/gustav
Pat what if I only need Fld B or Fld C....they don't have to both but the total goes into fld D...
Also how do I tie it back into my table for Fld D??
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
It is brave of you to try.  There are lots of videos and papers on the web that will help you learn faster.
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
Look for Access videos by Crystal.  She does a lot of basic stuff and she writes well also.