How to reach through subform to underlying table?

W

WDSnews

With VBA I've learned to pull data from fields on my subform like this:
sbfVendorDetail.Form.[Start Date]. However, fields such as the ID may not
be on the subform since the user doesn't need to see it and it would take up
space. Is there a way to read the ID field of the current record of the
subform without putting the field on the form?
 
D

Dirk Goldgar

WDSnews said:
With VBA I've learned to pull data from fields on my subform like this:
sbfVendorDetail.Form.[Start Date]. However, fields such as the ID may not
be on the subform since the user doesn't need to see it and it would take
up space. Is there a way to read the ID field of the current record of
the subform without putting the field on the form?


If the field is in the form's (subform's) recordset -- that is, included in
whatever set of fields are selected by the form's recordsource query -- then
you can access it the exact same way:

Me.sbfVendorDetail.Form.[ID]

In some circumstances you may find that you need to prefix the field name
with a bang (!) instead of a dot (.), like this:

Me.sbfVendorDetail.Form![ID]

If the field is not in the form's recordset, though, you can't do that.
 
A

Arvin Meyer [MVP]

The easiest method is to put it on the form or subform and set its Visible
Property to False. Then you can call it the same way.
 

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