R
raylopez99
I am trying to return the results of a SQL query in an Event
Procedure, that returns the number of rows (COUNT) that satisfies
something. I ran the query manually and I get "five" hits for "Table
1" below.
But when I run the query programmically (see the below--it's the first
time I've tried to run a parametized SQL query within Visual Basic), I
always seem to get a RecordCount of 1. Is RecordCount the number of
hits returned by a SQL query, or is it something else? If something
else, what property from the Recordset object will give the number of
hits returned by a SQL query?
Please advise.
If it matters, here is the simple SQL query that I call "Query1" and
yields five hits for the letter 'a' in field Text for the table Table1
I'm using: SELECT Count(*) AS MyCount1 FROM Table1 WHERE
(((Table1.Text1)=[Text]));
RL
Private Sub OUTPUT_Click() '<--this is a textbox OUTPUT and the Event
is "Click"
Dim rs As DAO.Recordset 'holds query resultset
Dim db As DAO.Database
Dim qdfParmQry As QueryDef 'actual query object
Set db = CurrentDb
Set qdfParmQry = db.QueryDefs("Query1") '<--the name of the query is
Query1
qdfParmQry![Text] = "a" <--if "a" is input into the query, you get
five (5) hits in Query1
'qdfParmQry("TEXT") = a 'this format didn't work, despite a source on
the Net saying it would
Set rs = qdfParmQry.OpenRecordset()
Dim TempVar As Variant
TempVar = rs.RecordCount ' I assign rs.RecordCount to a temporary
variable but same thing: always get 1
If TempVar = 1 Then
Dim msg1 As String
Dim title As String
'Dim style As MsgBoxStyle
Dim response
msg1 = "rs.RecordCount is always 1???!!!" ' Define message.
title = "MsgBox Output" ' Define title.
' Display message.
response = MsgBox(msg1, 3, title)
End If
End Sub
Procedure, that returns the number of rows (COUNT) that satisfies
something. I ran the query manually and I get "five" hits for "Table
1" below.
But when I run the query programmically (see the below--it's the first
time I've tried to run a parametized SQL query within Visual Basic), I
always seem to get a RecordCount of 1. Is RecordCount the number of
hits returned by a SQL query, or is it something else? If something
else, what property from the Recordset object will give the number of
hits returned by a SQL query?
Please advise.
If it matters, here is the simple SQL query that I call "Query1" and
yields five hits for the letter 'a' in field Text for the table Table1
I'm using: SELECT Count(*) AS MyCount1 FROM Table1 WHERE
(((Table1.Text1)=[Text]));
RL
Private Sub OUTPUT_Click() '<--this is a textbox OUTPUT and the Event
is "Click"
Dim rs As DAO.Recordset 'holds query resultset
Dim db As DAO.Database
Dim qdfParmQry As QueryDef 'actual query object
Set db = CurrentDb
Set qdfParmQry = db.QueryDefs("Query1") '<--the name of the query is
Query1
qdfParmQry![Text] = "a" <--if "a" is input into the query, you get
five (5) hits in Query1
'qdfParmQry("TEXT") = a 'this format didn't work, despite a source on
the Net saying it would
Set rs = qdfParmQry.OpenRecordset()
Dim TempVar As Variant
TempVar = rs.RecordCount ' I assign rs.RecordCount to a temporary
variable but same thing: always get 1
If TempVar = 1 Then
Dim msg1 As String
Dim title As String
'Dim style As MsgBoxStyle
Dim response
msg1 = "rs.RecordCount is always 1???!!!" ' Define message.
title = "MsgBox Output" ' Define title.
' Display message.
response = MsgBox(msg1, 3, title)
End If
End Sub