B
BrianB via AccessMonster.com
I am using the following query in my code to count the number of records
associated with a selected Client. I originally generated this SQL statement
in the query wizard and it worked fine and returns the right number of
records (of course asking me the for the client number [fselectrecd] which
normally comes from a combobox). I copied the code directly from the query
into my VBA code.
This code always returns a value of 1, even if there are 0 records.
When I "hover" over the [Forms]![fcontribution]![fSelectRecd] when I break
for debugging it shows the correct client number to count. I even tried VAL()
& VAL(TRIM()) on the combobox field in case a field type mismatch existed. I
also tried without the extra brackets the query builder put in.
Suggestions please
Dim strSQL As String
Dim rstAny As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
strSQL = "SELECT Count(*) as Expr1 FROM Contribution " _
& "WHERE (((Contribution.ClientID)=" & [Forms]![fcontribution]!
[fSelectRecd] & "));"
Set rstAny = db.OpenRecordset(strSQL)
RecdCount = rstAny.RecordCount
associated with a selected Client. I originally generated this SQL statement
in the query wizard and it worked fine and returns the right number of
records (of course asking me the for the client number [fselectrecd] which
normally comes from a combobox). I copied the code directly from the query
into my VBA code.
This code always returns a value of 1, even if there are 0 records.
When I "hover" over the [Forms]![fcontribution]![fSelectRecd] when I break
for debugging it shows the correct client number to count. I even tried VAL()
& VAL(TRIM()) on the combobox field in case a field type mismatch existed. I
also tried without the extra brackets the query builder put in.
Suggestions please
Dim strSQL As String
Dim rstAny As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
strSQL = "SELECT Count(*) as Expr1 FROM Contribution " _
& "WHERE (((Contribution.ClientID)=" & [Forms]![fcontribution]!
[fSelectRecd] & "));"
Set rstAny = db.OpenRecordset(strSQL)
RecdCount = rstAny.RecordCount