Question on DCount

TheEvilBankers

Registered User.
Local time
Today, 21:36
Joined
Aug 13, 2003
Messages
33
What I want is for DCount to see how many times a a Box# appears in a table, if it is 0 it puts a message up that the box does not exist.

This is what I have as the code

If DCount("[tblLockbox]![LockboxNo]", "[tblLockbox]", "[tblLockbox]![LockboxNo]=" & Me.[txtGLockbox]) = 0 Then
MsgBox "Lockbox not Found! Please try again.", vbCritical
Me!txtGLockbox.SetFocus
End If

tblLockbox is the table that contains all the lockbox numbers and the names they relate too.

LockboxNo is the field that holds the Box#. I have the field set as a Text because no calculations are done with these values.

txtGLockbox: is the field on the form where they enter the Box#

The problem is I keep getting a data type mismatch in criteria expression.
I thought DCount took a count and returned a value, so it shouldn't matter what data type the field in question is.

We are using it in another area where the field in question is a number.

I hope this makes sense.

Kim
 
When the user enters the Box# this is of course a number. You are trying to match this to a text field. I don't know why you decided to hold this as text, but there you go. You need to use CStr() to connvert your user input integer to a string.
 
Neil and Pat,

Thanks so much for your assistance.

Soon as you both mentioned the text bit and I looked at the quotes I realized what had been done.

The person who programmed this was trying to do things right and if it is not used for calculations she has them as text.

Kim
Who is need of a Starbucks run.
 

Users who are viewing this thread

Back
Top Bottom