Dcount help

R

rdonges

Is it not possible to reference the value of a control on a form for the
criteria in a Dcount function? The example in Access' help don't state this
explicitly. If you can only use constants as the criteria in Dcount, then
its usefulness is extremely limited. Here's what I'm trying to do, and it
only returns "0" no matter how many records match the criteria:

Dim numPermits As Integer
numPermits = DCount("[MemberID]", "tblPermits", "[MemberID] =
'frmPermitsMain!cboMemberID.Value'")

The fact that all I get is zeros tells me Dcount thinks my criterion is a
constant, and it isn't even looking at the combo box. Is it possible to use
a reference to a control or to use a variable for the criteria in Dcount?
Any answers or suggestions are greatly appreciated.

Randy Donges
 
R

rdonges

Thanks for the reply. MemberID is a string value, and the function will
work in the following format:

numPermits = DCount("[MemberID]", "tblPermits", "[MemberID] = '" &
Forms![frmPermitsMain]![cboMemberID].Value & "'")


I got this example in another reply and found out that if Forms! isn't
included, an error is returned. Thanks again for replying.

Randy Donges



Ron Weiner said:
if MemberID.Value is a string Try

numPermits = DCount("[MemberID]", "tblPermits", "[MemberID] = ' " &
frmPermitsMain!cboMemberID.Value & "'")

if MemberID is a number Try

numPermits = DCount("[MemberID]", "tblPermits", "[MemberID] = " &
frmPermitsMain!cboMemberID.Value )

Ron W

rdonges said:
Is it not possible to reference the value of a control on a form for the
criteria in a Dcount function? The example in Access' help don't state this
explicitly. If you can only use constants as the criteria in Dcount, then
its usefulness is extremely limited. Here's what I'm trying to do, and it
only returns "0" no matter how many records match the criteria:

Dim numPermits As Integer
numPermits = DCount("[MemberID]", "tblPermits", "[MemberID] =
'frmPermitsMain!cboMemberID.Value'")

The fact that all I get is zeros tells me Dcount thinks my criterion is a
constant, and it isn't even looking at the combo box. Is it possible to use
a reference to a control or to use a variable for the criteria in Dcount?
Any answers or suggestions are greatly appreciated.

Randy Donges
 

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

Access Dcount (multiple criteria) 3
DCount alwaysreturning 1 0
Access MS Access DCount function problem 0
DCount 2
Help with dCount - “Data Type mismatch in criteria expression†2
Dcount on Form 3
DCOUNT Help 2
Dcount operation 2

Top