Full Version: dcount issue
UtterAccess Forums > Microsoft® Access > Access Forms
My Dcount is not working... Here is the code I am using.
im dbsInv As DAO.Database
Dim SQLInv As String
Dim rstINV As Recordset
Dim sINV As String
Set dbsInv = CurrentDb()
SQLInv = "SELECT Acct_INFO.INV FROM Acct_INFO WHERE Acct_INFO.Acct_NUM = " & Me.txtAcctNum & ""
Set rstINV = dbsInv.OpenRecordset(SQLInv, dbOpenSnapshot)
sINV = rstINV!Inv
If DCount("[RefPkg]", "Inv_Ref_Pkg", "[Inv] =" & sINV) = 0 Then
Me.txtRefPkg = "Simple Package"
Me.txtRefPkg = DLookup("[RefPkg]", "Inv_Ref_Pkg", "[Inv] =" & sINV)
End If
Set rstINV = Nothing
Set dbsInv = Nothing
If there are no records in Inv_Ref_Pkg with the matching invoice, you will be returning a null value which will not evaluate to 0. Use the Nz function to force the 0:
If Nz(DCount("[RefPkg]", "Inv_Ref_Pkg", "[Inv] =" & sINV),0) = 0 Then
Thank you. it worked.
You're welcome. Glad I could help.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.