I am not a VB or VBA junkie... nor am I that great with databases either, but I am learning out of neccessity at the moment. Please bear with me.
I need to check if a record exists in a certain table and return a value if it does or doesn't in VBA. I know how to use COUNT and a SELECT query, but how do I return the value as a variable if there was any records or not?
Prolly a dumb question, but I have been thrown into this and I am learning as I go...
I was kinda getting there myself, but slowly. I picked up a couple of books on VB, VBA, designing Database Applications and another one on SQL. Looks like this will be my major focus at work from now on, so you will be seeing my posts here a lot until I figure things out.
if all you need is a count (i.e. you are not about to do something else with the recordset) why mess with a recordset.
domain aggreagate functions do all the single-answer stuff you need on a domain: count, max, min, sum etc etc etc
if its a stored query:
myVar = Dcount("[aFieldToCount]", "myQueryName")
...this doesn't count aFieldToCount=null
or perlgurl's question:
myVar = Dcount("[pin]", "tblSurvey", "[pin] = 1234")
...i leave you to sort out the concatenation of a variable into the criteria section - my brain is not in gear on new years day.