views:

598

answers:

2

I have a table titled MIUInfo. In it there are three columns; MIUID, Latitude, and Longitude.
In it I'm running the following query which gets the number of MIUIDs in the criteria range.

SELECT Count(MIUInfo.MIUID)
      From MIUInfo 
      WHERE ((MIUInfo.Latitude Between " & minLat & " And " & maxLat & ") 
      AND (MIUInfo.Longitude Between " & minLong & " And " & maxLong & "))

I need to set the result of this query equal to a variable in VBA so that I can use it as a condition for a loop. I can't figure out how to do this.

Also, when I try to use the DoCmd.RunSQL command I get an error:

Run-time error '2342': A RunSQL action requires an argument of an SQL statement.

The only difference between this query and others I'm running with the DoCmd.RunSQL is that all of the other select queries are generating a new table.

A: 

In Access the easiest way to do this is with the DCount function:

Total = DCount("MIUInfo.MIUID", "MIUInfo", "(MIUInfo.Latitude Between " & minLat & " And " & maxLat & ") AND (MIUInfo.Longitude Between " & minLong & " And " & maxLong & ")")
Robert Harvey
Worked like a charm, Thanks.
Bryan
A: 

Use DCOUNT

Sev