Populate a subform using VBA

X

XP

Using Office 2003 and Windows XP;

Is there a way to populate a subform using the results of a recordset using
VBA?

If so, could someone please post a generic VBA example?

Thanks much in advance.
 
M

Marshall Barton

XP said:
Using Office 2003 and Windows XP;

Is there a way to populate a subform using the results of a recordset using
VBA?

If so, could someone please post a generic VBA example?


That's a pretty generic question, so I guess a generic
answer is about all I can provide ;--)

Set Me.subformcontrol.Recordset = rs
 
X

XP

Thanks Marshall,

I have really tried everything I can think of and nothing works.
Included in my tries are:

Me.sfrmData1.Form.RecordSource = sSQL

and now: Set Me.sfrmData1.Form.Recordset = adoRS

I get an error saying that the object I'm referencing is closed; it is a
subform on an open form and there is no code anywhere that closes it. The
form is not bound. I have checked the SQL and the form name and even popped
it up in a message.

Do you have any other ideas/suggestions? I must be doing something patently
wrong.

I even trashed and rebuilt the subform, but still the same problem.
 
M

Marshall Barton

I see that you corrected for my ommission of the Form
property. Thanks for that.

I don't use ADO, but I doubt that it's any different from
DAO in this kind of thing. Both of the things you tried are
the right way to do this so, assuming that adoRS is open) I
don't have anything to add to that.

Since a subform's open event occurs before the main form's
events, I don't see how it can say the form object is not
open (unbound shouldn't matter). At this point, the only
straw I can see to grasp at here is if sfrmData1 is not the
name of the subform **control**, but if that were the case,
you should get a different message.
 
R

RoeCastle

you have to write a statement to setfocus on the subform before you can
populate it. I had the same problem and I kept trying to populate it while
the focus was still on the main form. Hope this helps.
 
Top