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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble Referencing subForm Properties 3

Status
Not open for further replies.

alr0

Programmer
May 9, 2001
211
0
0
US
Hi All,

I am trying to requery a subform after adding a record. Using vba in Access 02 I put the following code in the onClose event of the form for adding records.

Forms!frm201!sbf211.Requery

I get this error message

Microsoft Access can't find the field "sbf211" referred to in your expression

I found a syntax described for referencing subForm controls as follows

Forms!frm201!sbf211.Forms.Requery

The same error message comes up. I found a kb article suggesting the recordsource be set to "", then reassigned so I tried this code.

Forms!frm201!sbf211.Forms!RecordSource = ""
Forms!frm201!sbf211.Forms!RecordSource = "qry211"

I am out of things to try. Perhaps properties are accessed differently than controls but I can't find a description. Any suggestions would be much appreciated.

Thanks,

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Good morning alr,

I think you are referring to the name of the subform rather than the subform (Child) control. The subform control is the container that holds whatever subform you designate and is what you need to reference.

When you add a subform (lets call it sfm1) to a parent form, Access automatically creates the subform control and names it after the subform, thereby usually dodging subsequent syntax reference problems.

Therefore when you refer to what you think is the subform (sfm1), Access looks to the subform control, but no problem since the names are they same.

However if you subsequently change the name of the subform (which I suspect you have done), now you have lost Access.

Also, you may wish to use the following syntax: it is a bit more explicit and a wee bit faster, though it requires a few extra keystrokes. Flexibility has its uses, but is also confusing.

Forms("frm201")("sbf211").Requery is equivalent to Forms!frm201!sbf211.Requery

Cheers,
Bill


 
How are ya alr0 . . . . .

So close, yet, so far away . . . . .
Code:
[blue][purple]Change:[/purple]
   Forms!frm201!sbf211.[b]Forms[/b].Requery
[purple]To:[/purple]
   Forms!frm201!sbf211.[b]Form[/b].Requery[/blue]
[blue]Forms[/blue] is the [blue]Forms Collection[/blue].
[blue]Form[/blue] is a [blue]Form Object[/blue].

Calvin.gif
See Ya! . . . . . .
 
THanks to AceMan for the correction. Close won't count.

Forms("frm201")("sbf211").Requery is equivalent to Forms!frm201!sbf211.Form.Requery and both will work.

Cheers,
Bill
 
How are ya formerTexan . . . . .

Yes . . . . one references the control, the other the form. However [blue]alr0[/blue] was using the [purple].Form[/purple] method!

Calvin.gif
See Ya! . . . . . .
 
When referencing subform controls and properties, remember that what's used in the reference is the subform control name, which may differ from the subform name as viewed in the database window.

Easiest way of obtaining the correct reference, would be to invoke the expression builder, for instance from the criteria row of a qery while the form is open. Doubleclick thru forms, loaded forms, main form, subform and a control on the subform. This will provide the correct reference.

As for referencing thru
[tt]Forms!frm201!sbf211.Form.Requery ' or
Forms("frm201")("sbf211").Form.Requery ' or even
Forms("frm201").controls("sbf211").Form.Requery[/tt]

or for subform on the current form
[tt]Me!sbf211.Form.Requery ' or
Me("sbf211").Form.Requery ' or even
Me.controls("sbf211").Form.Requery[/tt]

is pretty much preferences. Some info can be found here How to refer to a control on a subform or subreport in Access 2000.

The reference:
[tt]forms!mainform!subformcontrolname.someproperty[/tt]

would refer to one of the properties of the subform control, as for instance the sourceobject, visible... whilst to address subform properties, one would usually need to add the form keyword. However, it seems Access accepts less fully qualified referencing from time to time.

Roy-Vidar
 
Thanks to All,

I can't imagine how I have lived all these years without knowing that syntax. Everthing works fine now.

Thanks again,

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top