SQL Query on a button

  • Thread starter Thread starter -LeguMan-
  • Start date Start date
L

-LeguMan-

Hello,

I'm looking for a way to execute a SQL request. This request must be hard
coded and lauched from a button in a form.

I was trying somthing like this but it doesn't work ...


Dim rst As New ADODB.Recordset, cnn As New ADODB.Connection

Set cnn = CurrentProject.Connection
StrSQL = "Select famille.ID FROM famille WHERE famille.ID = 'Toto'"
rst.Open StrSQL, cnn, adOpenForwardOnly, adLockReadOnly
msgbox (rst.RecordCount)
rst.Close
Set rst = Nothing
Set cnn = Nothing


Can someone Help ?

PS : the result of the query must be in a recordset.

Thanks,
LeguMan
 
Hi,
Read up on the record count property for ado recordsets:

The cursor type of the Recordset object affects whether the number of
records can be determined.

The RecordCount property will return -1 for a forward-only cursor; the
actual count for a static or keyset cursor;

and either -1 or the actual count for a dynamic cursor, depending on the
data source.



You are using a foreward only cursor, hence no recordcount

HTH

Dan Artyso, MVP
 
Back
Top