Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for refering to a subform 2

Status
Not open for further replies.

nathanstevenson

IS-IT--Management
Oct 4, 2002
70
GB
Hello,

I have a main form: frmMasterTimesheet. Then I have created a subform, sbfrmJobDetails, which is linked to the Parent form.

Now I have a 3rd form sbfrmTimesheet. from this subform, how do I refer to sbfrmJobDetails?

Basically I want to click on subfrom 1 and have the linked
stuff displayed on subform 2.

Any ideas?

Nathan
 
Try this:

=[Forms]![frmMasterTimesheet]![sbfrmJobDetails].[Form]!["FieldName"]

Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Nathan,

Yeah, this is a good little trick you're onto. Anthony's answer on how to reference the other subform is correct, but depending on what you're trying to do, may not be necessary. In general, the way to refer to a subform is:
forms!NameOfMainForm!NameOfControlThatHoldsSubform.form
and from there you tack on either:
.NameOfPropertyOfTheSubform
or
!NameOfControlOnTheSubform

But if what you've got going on is two subforms on the same form, and you want the rows of subform2 to be keyed to the record selected in subform1, you can do without that.

I have a form that tracks Accounts. There's one subform that holds Discrepancies found in the account and one subform that lists who received e-mails about the discrepancy that's selected in the first subform.

Making it work is rather simple. In the first subform's OnCurrent event I have a single line of code:
Me.Parent!txtDiscrepancyID = Me!txtDiscrepancyID
This sets an invisible control on the main form to the Primary Key value of the stuff in the first subform. The second subform has it's Link Master Field set to that control on the main form. This means that every time I change records in the first subform, the records in the second subform are updated to be relevant to the newly selected record in that first subform.

If that's what you're trying to do, you won't have to refer to the second subform at all. But I'm just guessing that that's what you're trying to do.

Hope this helps.

Jeremy =============
Jeremy Wallace
AlphaBet City Dataworks

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Hi there,

So far so good! Thanks Jeremy, you were right, I am trying to sync two subforms automatically.

I have managed to get the txtDummyID working smoothly. The problem now is that when I try and link the second subform, it gives an error "The expression you entered refers to an object that is closed or doesn't exist".

It will link on the primary key of the recordset of the main form, but it doesn't seem to want to link to the txtDummyID.

Any ideas?
 
Sorry, let me elucidate a bit.

How do I link subform B to a control like a text box in the main form, when in general, subforms link to a field from the record that the main form is set at?

 
Nathan,

You can just put the name of the _control_ (txtDummyID on the main form) as the Master Link Field and put in the name of the appropriate _field_ (on the second subform) as the Child Link Field.

For testing purposes, keep txtDummyID visible, so you can make sure it's updating.

You say you get that error when you put in the link fields. Is that really when it happens, or does it happen when you attempt to view the main form?

Jeremy =============
Jeremy Wallace
AlphaBet City Dataworks

Take a look at the Developers' section of the site for some helpful fundamentals.
 
That's it ... sorted!

Thanks so much... now the rest of my app (screen at least)
should be easy going.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top