Datasheet's Recordset

P

Peter

Hello,

I am having difficulty in setting my recordset to my subform which is setup
as a datasheet. My code is as follows:

'I've already declared my ADO objects and subform as class level variables.
'This procedure occurs from the main form's module.
Private Sub GetRecords()
Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset

strSQL = "SELECT strName, intNumber, lngAmount " & _
"FROM tblTest"

With rs
Set .ActiveConnection = cnn
.Source = strSQL
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockReadOnly
.Open
End With

Set sfrmTest.Recordset = rs

'Clean up.
Set cnn = Nothing
Set rs = Nothing

cnn.Close
rs.Close
End Sub

I usually get an empty datasheet even though my recordset does contain rows
of data. I've tried looping through the recordset, but that just gives me
repeated data from the recordset's last row. Any help would be appreciated.

Thanks,

Peter
 
R

Rob Oldfield

You're overcomplicating. No recordset needed.

me.subformcontrolname.form.recordsource=strsql
 
P

Peter

Thanks. I tried it but my datasheet is blank. I have the correct number of
rows, but with no data. Thanks.
 
R

Rob Oldfield

Huh? Just to check this... you have rows showing on the subform... but with
no data displayed in them?
 

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