SQL Query on a button

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
 
D

Dan Artuso

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top