rst for subform

J

Jason

Hi,

Can anyone help me with setting a recordset in a subform?

I've this code where i use the connection method to connect to a sql server
database. I can use it to set the recordset in a form and a subform, but
when i go the next record in the main form the subform's recordset stays the
same.

Here is the code:

Private Sub Form_Open(Cancel As Integer)

Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset

With rst
.Source = "SELECT * FROM MyTable1"
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.ActiveConnection = GetConnection(True)
.Open
End With

Set Me.Recordset = rst ' this is for the main form

Set rst = Nothing

End Sub

for the subform it goes somewhat the same. Anyone knows the problem?
 
V

Van T. Dinh

I would assume you will need to create a different Recordset for the Subform
(since this will only contains child Records related to the new Current
Record on the Main Form) since the previously-assigned Recordset for the
Subform is no longer valid.

I think you need to use the (Main) Form_Current Event to do the above.
 
J

Jason

I did that and it did gave me a recordset which belongs to the parent. The
problem is when going to the next record, the childrecord doesn't change.
 
V

Van T. Dinh

Have you tried that in the Form_Cureent Event?

Post your code if you don't mind.
 

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