Error on Empty Table

D

DS

I have these two DSum statements that I get an Error on because the table is
Empty.

Me.TxtDebit = Nz(DSum("[GiftAmount]", "tblGiftCardDetails", "GiftCardNumber
= " & Forms!frmFXGiftManager!TxtGiftID And GiftDebit = -1), 0)

Me.TxtCredit = Nz(DSum("[GiftAmount]", "tblGiftCardDetails", "GiftCardNumber
= " & Forms!frmFXGiftManager!TxtGiftID And GiftDebit = 0), 0)

When I try to run the code. The VBA editor pops up with the DSum in yellow.
When I put th ecursor over the GiftDebit field in the statement it says
empty. How can I fix this?
Thanks
DS
 
D

Dirk Goldgar

(re-posting -- I don't see my original reply)

DS said:
I have these two DSum statements that I get an Error on because the table
is Empty.

Me.TxtDebit = Nz(DSum("[GiftAmount]", "tblGiftCardDetails",
"GiftCardNumber = " & Forms!frmFXGiftManager!TxtGiftID And GiftDebit
= -1), 0)

Me.TxtCredit = Nz(DSum("[GiftAmount]", "tblGiftCardDetails",
"GiftCardNumber = " & Forms!frmFXGiftManager!TxtGiftID And GiftDebit = 0),
0)

When I try to run the code. The VBA editor pops up with the DSum in
yellow. When I put th ecursor over the GiftDebit field in the statement it
says empty. How can I fix this?


I don't think it's because the table is empty. I think it's because your
criteria argument is malformed. Am I right in thinking that GiftDebit is a
field in the table, and you want to sum records where the GiftCardNumber
field is equal to the TxtGiftID value from the form, and the GiftDebit field
= -1 (True) in one case, and 0 (False) in the other case? If so, then try
these versions of the statements instead:

Me.TxtDebit = _
Nz(DSum("[GiftAmount]", "tblGiftCardDetails", _
"GiftCardNumber = " & Forms!frmFXGiftManager!TxtGiftID & _
" And GiftDebit = -1"), 0)

Me.TxtCredit =
Nz(DSum("[GiftAmount]", "tblGiftCardDetails", _
"GiftCardNumber = " & Forms!frmFXGiftManager!TxtGiftID & _
" And GiftDebit = 0"), 0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DSum Problem 2
Need help to Simplify a Complex Calculation on a Form 0
Function Returns 0 3
#Error msg on form 8
SEE THIS DATE 8
Form Reference 5
DSUM with empty tables 1
Checking for Empty Table 2

Top