DLookup returns Null!!

Bee

Registered User.
Local time
Today, 10:51
Joined
Aug 1, 2006
Messages
487
Hi,

I wrote the code below in a module. The text box that this part of the code is getting its value from has a DLookup in its control source. The problem is that when the DLookup does not match the criteria it looks for, it returns Null. The code tries to assign Null to a variable of type currency and that returns an error. Is there anyway to convert the Null to 0?

What do you suggest?

Returns DLookup value:
Code:
Forms![frmHouse]![qryHouse4].Form![txtTotalVO].Text


All the function:
Code:
Public Function CalculateDepositPlusVO()
    Dim vAgreedPrice As Currency
    Dim vtxtTotalVO As Currency
    Dim vtxtAgreedPricePlusVO As Currency
    
    Forms![frmHouse]![qryHouse4].Form![AgreedPrice].SetFocus
    vAgreedPrice = Forms![frmHouse]![qryHouse4].Form![AgreedPrice].Text
    Forms![frmHouse]![qryHouse4].Form![txtTotalVO].SetFocus
    vtxtTotalVO = Forms![frmHouse]![qryHouse4].Form![txtTotalVO].Text
    vtxtAgreedPricePlusVO = vAgreedPrice + vtxtTotalVO
    Forms![frmHouse]![qryHouse4].Form![txtAgreedPricePlusVO].SetFocus
    Forms![frmHouse]![qryHouse4].Form![txtAgreedPricePlusVO].Text = vtxtAgreedPricePlusVO
End Function


Any help will be very much appreciated,
B
 
you can do

iif (isnull(yourdlookupvalue),0,yourdlookupvalue)
 
I usually use a DCount first to see if there are any records that exist and if not then I don't run the DLookup.
 
That's brilliant. Thanks very much.
 
Or wrap the DLookup() in an Nz() function.
 

Users who are viewing this thread

Back
Top Bottom