Yes, Brook, that's what it should do.
Now that you have that working, you can go back to the beginning of this
thread, and use the working expression in the first argument of DSum(),
such
as:
DSum("CCur(Nz([Credit],0) + Nz([Debit],0))", "tblcheckingaccount", "[ID]
<=
" & [ID])
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Hello Allen,
Debit Column: Values are Negative, and the column can contain Null
Values and contains only Debits
Credit Column: Values are Positive, and the column can contain Null
Values and contains only Credits
I did create a new column and added the code that you provided, and
what
it does is create a new column with all my debits and credits only no
running
balance? Is that what is should do?
Or do I need to added the column Expr1:
DSum("Debit_Credit","tblcheckingaccount","[ID] <= " & [ID])
Thanks very much for all your help & your patience!
Brook
:
You will need to sort out the details, because I'm not clear if the
Debit
values are negative, or whether the records can have both a Credit or
Debit,
or whether Nulls are allowed in either field, but you could try
something
along these lines:
Debit_Credit: CCur(Nz([Credit],0) + Nz([Debit],0))
Nz() deals with the cases where one field is null.
CCur() converts the result to Currency so JET can't get it wrong.
The plus needs to be a minus if the Debit column values are not
negative.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
The reason for the code that I posted, is that I created a single
column
for all debits and credits from the individual fields "Debit" &
"Credit",
thinking that it would be easier to create a running balance, but I
guess
I
was mistaken.
Would it be easier to create a "running balance" from my
individual
Debit
& Credit Fields?
Thanks,
Brook
:
Yes, it does matter, Brook.
The previous request about the Debit_Credit field was so as to
determine
whether JET might be misinterpreting the data type of the field. If
it
is
not a Currency field in a table as you reported, but a calculated
query
field, this issue does apply. For details, see:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html
However, the expression itself could also be the problem. You are
comparing
Debit to True. If Debit is a Yes/No field, that makes sense, but
the
rest
of
the expression does not. If Debit is a Currency field, I'm not sure
why
you
would only want the value of the Debit field when it happened to
be -$1.00.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Thanks for all your help,
I cannot get it to work, but will keep trying.
I'm not sure if this matters, but the Debit_Credit Field is
calculated
as:
Debit_Credit: IIf([Debit]=True,[Debit],[Credit])
Thanks again,
Brook
:
Then, keep working on it, Brook.
You can sum a Currency field without problem, and the 3rd
argument
is
correctly formed for a Number type field that can't be null.
Allen,
ID is an autonumber field and Debit_Credit is a currency
field.
Thanks for the response...
Brook
:
If you open your table in design view, what data type are the
2
fields:
ID
Debit_Credit
?
hello Allen,
I tried typing the following into a new column, but am
getting
no
results
in the column, once I run the query? Any ideas?
Expr1: DSum("Debit_Credit","tblcheckingaccount","[ID] <= "
&
[ID])
Thanks,
Brook
:
Try typing this into a fresh column in the Field row in
query
design:
DSum("Debit_Credit", "Table1", "[RecordID] <= " &
[RecordID])
Substitute your table name for Table1, and your primary
key
field
for
RecordID.
That should work unless you filter or sort the fields
differently.
Note that DSum() will be slow to execute on every line of
your
query.
I am trying to create a running balance for my checking
account
Debit_Credit Field.
I have been reading about DSUM, but am unsure how to
use
it?
each
of
my
records has a disctinct recordid.