DCount() question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to use DCount to count the number of records with a particular
employee number. The employee number is contained in a combo box and is
picked by the user. The final count is then stored in a text box on my form.
It looks something like this: .....txtCount = DCount("datDate", "tblX",
"txtID = cboName.Column(0)"). datDate signifies the date that a button was
pushed. I'm getting an "Undefined function 'cboName.Column' in expression"
error. Any thoughts?

Nick
 
Assuming the ID field is numeric:
......txtCount = DCount("datDate", "tblX", "txtID = " & cboName.Column(0))
If it is text, try:
......txtCount = DCount("datDate", "tblX", "txtID = """ & cboName.Column(0) &
"""")
 
ndunwoodie said:
I'm trying to use DCount to count the number of records with a
particular employee number. The employee number is contained in a
combo box and is picked by the user. The final count is then stored
in a text box on my form. It looks something like this:
.....txtCount = DCount("datDate", "tblX", "txtID =
cboName.Column(0)"). datDate signifies the date that a button was
pushed. I'm getting an "Undefined function 'cboName.Column' in
expression" error. Any thoughts?

You should move the control reference outside of the quoted criteria
expression. Also, if you want to just count records, it would be more
efficient to use "*" instead of "datDate" (which I presume is tee name
of a field in "tblX". The Dcount() expression would then look something
like this:

DCount("*", "tblX", "txtID = " & Me!cboName.Column(0))

That assumes that txtID is a number field, not text.

If cboName.Column(0) is the bound column of the combo box, you can just
write this:

DCount("*", "tblX", "txtID = " & Me!cboName)
 
You need to take cboName.Column(0) outside, try this

If txtID is string type
txtCount = DCount("datDate", "tblX", "txtID = '" & cboName.Column(0) & "'")

If txtID is Number type
txtCount = DCount("datDate", "tblX", "txtID = " & cboName.Column(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


Back
Top