Retrieve parent form current record from a subform

G

Guest

I need to know the value of a master field from a subform (a reference to the
subform is stored in frm object). I use

frm.Parent.Recordset.Fields(master_fld_name).Value

but it always returns the value of the first record. For example: the parent
form contains a combobox with values 111, 222, 333. The field linked with the
combobox is a master field for my subform (the string variable
master_fld_name contains the name of this field). If I choose 111, the above
code returns 111. When I choose 333, the code also returns 111. I can't
understand why it does not return the value for a current record.
 
G

Guest

Hi Ian yu,

The code you are using is referencing the recordset, which is why it is
always showing you the first record (rather than the selected record).

Try using me.parent.form.COMBOBOXNAME to reference the field you are after.

Hope this helps.

Damian.
 
G

Guest

Thanks for your reply, Damian. The problem is I'm making a universal tool
that should work for any open form and thus I do not know the name of a
control linked to a master field beforehand. I wonder if there's a way to
retrieve current record without looping through all controls to find the ones
bound to master fields.
 
G

Guest

It seems I solved the issue.

Dim rst_parent As ADODB.Recordset

Set rst_parent = frm.Parent.RecordsetClone
rst_parent.Bookmark = frm.Parent.Bookmark

Then use rst_parent.Fields(master_fld_name).Value to retrieve values.
 

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