Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dcount problems using variables 1

Status
Not open for further replies.

JimmyFlynn

Technical User
May 4, 2002
3
GB
Hi!

This works ...

dim myresult as integer
myresult = dcount("[myfield]","mytable","[myfield]=12345")

This doesn't!

dim myresult as integer, mysearch as integer
mysearch = 12345
myresult = dcount("[myfield]","mytable","[myfield]=mysearch")

I get all sorts of sytax errors or type mismatch errors depending on how I syntax the criteria bit of the code. I've tried every symbol on the keyboard to try and get it right but "Failed" is not in my vocabulary.

Can anybody please guide me as to the correct syntax for using a variable on this occasion ... and before you ask "myfield" is an integer only field.

Jim
 
try this...

myresult = dcount("[myfield]","mytable","[myfield]=""mysearch""")

just an idea...

--Junior

JHauge@jmjpc.net
Life is change. To deny change is to deny life.
 
Hhhmmmm ....

Run-time error '3464':

Data type mismatch in criteria expression

This seems to say that mysearch and myfield are not compatible ... checked the table and the filed property is set to integer???

Any other ideas?

Jim
 
Cracked it!!!!!!!!!

myresult = dcount("[myfield]","mytable","[myfield]=" & mysearch)

just a little ampersand makes all the difference B-)

Jim
 
there ya go:)
JHauge@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top