Newbie trying DCount Function

E

Ed Rawley

I have a database filled with 7 digit numbers, all unique,
that have been indexed. Need to find if the number exits
in table. I ran the following code at it and got an error
of "Datatype mismatch in criteria expresion". Any help
would be appreciated.

Private Sub btnSearch_Click()
' Stop if a value has not been entered
If IsNull([dblFindMe]) Or [dblFindMe] = "" Then
Exit Sub
End If

'otherwise
Dim strCrit As String
Dim i As Integer
Dim strmsg As String

strCrit = [dblFindMe]
i = DCount("[dblNumber]", "tbl216", "[dblNumber]='" &
strCrit & "'")
'set message based on wether the value is already in the
table
If i = 0 Then
strmsg = "Item Not Listed"
Else
strmsg = "Item is Already Listed."
End If
'dispaly message in a message box
MsgBox strmsg
End Sub
 
J

John Vinson

i = DCount("[dblNumber]", "tbl216", "[dblNumber]='" &
strCrit & "'")

If the field dblNumber is numeric, leave off the quotemarks; they're
only for Text type fields. Just use

"[dblNumber] = " & strCrit)
 

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

Top