Referencing a Specific Column in a Subform

D

Dirk Goldgar

L.A. Lawyer said:
I am trying to capture the value of the second column of the subform
identified as CaseListSubform, the name of the subform itself (ie, the
source object) is CaseList. The event is when I click on the first column
I must identify THE SECOND COLUMN. What is the reference path?

I have tried dozens of combinations


You don't normally refer to form fields ordinally; that is, by column
number. Normally you refer to them by name. For example, if the code is
running on the main form, you would write something like this:

varYourVariable = Me!CaseListSubform.Form!FieldName

If the code is running on the subform, it would be something like this:

varYourVariable = Me!FieldName

Do you really need to reference the field ordinally? The only reason I can
think of that you would need to do that is that you don't know at design
time what form object will be the source object of the subform control. If
you really have to do this, you can probably get at it by referring to the
subform's recordset:

(from main form:)

varYourVariable = Me!CaseListSubform.Form.Recordset.Fields(1)

(from the subform:)

varYourVariable = Me.Recordset.Fields(1)

You'll get an error if there is no current record on the subform, which
could happen if there are no records to display and the form or its
recordsource don't permit the addition of records.
 
L

L.A. Lawyer

I am trying to capture the value of the second column of the subform
identified as CaseListSubform, the name of the subform itself (ie, the
source object) is CaseList. The event is when I click on the first column
I must identify THE SECOND COLUMN. What is the reference path?

I have tried dozens of combinations
 

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