How to reach through subform to underlying table?

  • Thread starter Thread starter WDSnews
  • Start date Start date
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?
 
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.
 
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.
 
Back
Top