Dustin Stanley
asked on
Ms Access Dcount Help Please! Saying 0 when it is more than 0
Here is my code. They both are above 0 in count but:
Doesn't work:
Does Work:
Whole Code:
Please help! LocID and ProductID are both numeric. Sometimes the record count may only be 1.
Thanks!
Doesn't work:
If DCount("[LocID]", "[ProdLocations]", "[LocID] =" & Me.ProdLocLocID) > 0 Then
Does Work:
If DCount("[ProductID]", "[ProdLocations]", "[ProductID] =" & Me.ProductID) > 0 Then
Whole Code:
If DCount("[ProductID]", "[ProdLocations]", "[ProductID] =" & Me.ProductID) > 0 Then
If DCount("[LocID]", "[ProdLocations]", "[LocID] =" & Me.ProdLocLocID) > 0 Then
MsgBox ("IT EXISTS!")
Else
MsgBox ("Nothing!")
End If
End If
Please help! LocID and ProductID are both numeric. Sometimes the record count may only be 1.
Thanks!
ASKER
Still says Nothing Rey. It works without the criteria. As in it returns things.
ASKER
YES I figured it out! I thought I had this set up on LocID when it was supposed to be ProdLocID
This Code works:
This Code works:
Private Sub Command35_Click()
'If DCount("[ProductID]", "[ProdLocations]", "[ProductID] =" & Me.ProductID) > 0 Then
If DCount("[ProdLocID]", "[ProdLocations]", "[ProdLocID] =" & Me.ProdLocLocID) > 0 Then
MsgBox ("IT EXISTS!")
Else
MsgBox ("Nothing!")
End If
'End If
End Sub
ASKER
How can I combine these dcounts. I need the record to be >0 for both at the same time.
Exists
Else
Nothing
Exists
Else
Nothing
you can "AND" the dcount
Private Sub Command35_Click()
If DCount("[ProductID]", "[ProdLocations]", "[ProductID] =" & Me.ProductID) > 0 AND If DCount("[ProdLocID]", "[ProdLocations]", "[ProdLocID] =" & Me.ProdLocLocID) > 0 Then
MsgBox ("IT EXISTS!")
Else
MsgBox ("Nothing!")
End If
End Sub
ASKER
I tried that and there is a expected expression on the second AND If
oops, remove the second "If"
Private Sub Command35_Click()
If DCount("[ProductID]", "[ProdLocations]", "[ProductID] =" & Me.ProductID) > 0 AND DCount("[ProdLocID]", "[ProdLocations]", "[ProdLocID] =" & Me.ProdLocLocID) > 0 Then
MsgBox ("IT EXISTS!")
Else
MsgBox ("Nothing!")
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you but now it says everything exists. Is it reading a single record for both criteria? It seems like it is reading from all records in the table.
ASKER
Sorry I didn't see the second one. But the first one says everything exists and the second one says nothing.
it will read all records that satisfy both criteria.
use the last code I posted.
ASKER
So if in my table there is no single record that match both criteria then it says Nothing correct?
The last code says Nothing!
The last code says Nothing!
that is correct.
ASKER
Why and how is the wildcard * used here?
why? that is the way the function dcount() operates.
if you use the * ,the DCount function calculates the total number of records, including those that contain Null fields.
for more detailed explanation, type dcount in the access help window.
if you use the * ,the DCount function calculates the total number of records, including those that contain Null fields.
for more detailed explanation, type dcount in the access help window.
ASKER
Thanks I was just reading about that.
https://support.office.com /en-us/art icle/DCoun t-Function -f6b5d78b- ad0b-4e42- be7a-11a64 acbf3d3
I got it work thanks Rey!
https://support.office.com
I got it work thanks Rey!
ASKER
Thanks!
If DCount("*", "ProdLocations", "[LocID] =" & Me.ProdLocLocID) > 0 Then