PDA

View Full Version : Load Subform data using ADODB



jaykishan_82
01-10-2009, 12:59 AM
Dear Friends,

Need your help on below case.

I am trying to polulate data in Subform (like: dbgrid in VB) using ADODB recordset. But i show's only single record in Subform.

Please find the code and help of this matter?

Private Sub Cmd_Load_Click()

Dim Cn as ADODB.connection
Dim RstLoad as adodb.recordset

cn.open "Connection string of the database from which i want to populate in subform".

rstload.open ("Select * from "Table_Name"),cn

set me."subformname".form.recordset=rstload

do while not rstload.eof

me."subformname".controls("text1 name of subform")=rstload.fields("Name").value

rstload.movenext

loop

rstload.close
end sub

This code words fine but only bind single record from recordset and reflect in subform.

Kindly help ?

Regards,
JK

CreganTur
01-10-2009, 12:28 PM
welcome to the forum- always good to see new members!

When posting code, please wrap it in VBA tags (the green VBA button on your message window). This will format the code according to VBIDE, which makes it very easy to read.

To answer your question: The easiest way for you to accomplish what you want would probably be to load the contents of your recordset into a temporary table on your database. You can use a simple make table query to create the table and then load the recordset records into it. Then set your subform to query the values from the temp table.

Then when you're done you can just DROP TABLE on your temp table to clear everything out.

HTH:thumb