Subform data

J

Jeff

I have a subform that I want to populate with data from a query recordset.
In the form_open event I have

Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qry_Union_Single_Weekly_Monthly")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.name)
Next prm
Set rst = qdf.OpenRecordset()


'Checks to see if there is at least one record in the recordset
If rst.EOF = False And rst.BOF = False Then

this is where I need help.

I have set the link child fields of the subform to "MeetingDate" which is in
the recordset and set the link master fields to a text box on the form.
What is the rest of the process to populate this subform?
I know I could set the recordsource of the subform to the query and
eliminate this "openrecordset" method but for various reasons this is the
way I have elected to go.
 
S

Sandra Daigle

Hi Jeff,

Once you have a recordset open you can *set* the subform's recordset to it.
I am unclear as to whether you are opening this recordset using the open
event of the form or the open event of the subform but I think that it would
probably make more sense for it to be done in the Current event of the main
form so that you get a new recordset in the subform each time you move to a
new record in the main form. Also, if you are opening a recordset using
parameters, you might as well drop the linking fields for the subform and
just include MeetingDate in the filter for your recordset.

Assuming the code to open the recordset is in the mainform, you would simply
add the following line:

set me.sfrmMySub.form.recordset=rst

Replace 'sfrmMySub' with the name of your subform control on the main form.

One other thing I noticed - the following line is not quite right to catch
the empty recordset condition:

If rst.EOF = False And rst.BOF = False Then

Instead it should be

If not(rst.eof and rst.bof) then
'the rst has records
else
'the rst has no records
endif
 

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

Similar Threads

OLe Object ? 0
form parameter in SQL-INSERT 1
QueryDef 1
Running parameter query from code problems. 1
QueryDefs? Parameters? 4
QueryDef problem 3
Updating all records in a recordset 4
Trouble with lookup 1

Top