Syntax Problem in accessing a control on a form - Access97

  • Thread starter Thread starter Leonard Priestley
  • Start date Start date
L

Leonard Priestley

I have a main form (frmMain) which includes a subform (frmHost). I am using
the subform to display any one of several forms, selected by using a command
button which sets the form to be displayed as the SourceObject for the
subform. This works fine.

One of the forms to be displayed (frmToDo) is a continuous form with several
fields. Using command buttons, the user can select which field to sort the
data on. I want to preview and print the data from this form, sorted in the
same way as the user has selected for the form. I identify the command
button pressed by assigning a value to a variable (ReportSelect As Integer).
The value of ReportSelect assigned to an invisible textbox (txtRS), to be
picked up by the report.

When I tried to produce and run a report, it became evident that the sorting
of the data would have to be done before frmToDo processed the line:

DoCmd.OpenReport "rptToDo", acViewPreview

So I added code to the Report Open event, to do the sorting. I began by
picking up the value of txtRS from frmToDo, and then used a Select Case
statement to decide how to sort.

My problem is this: When I work only with frmToDo, and rptToDo, I use this
code to pick up the value of txtRS:

ReportSelect = Forms!frmToDo.txtRS,

and it all works beautifully. But when I take one step back and try to run
it from frmMain, I cannot get the syntax correct. At present I am looking
at the line:

ReportSelect = Forms![frmMain].[frmHost].frmToDo.txtRS

Which produces an error message 'Object doesn't support this property or
method'. I have tried removing [frmToDo] and get the same error message.

Can someone put me right on this please
..
Leonard Priestley
 
Leonard said:
I have a main form (frmMain) which includes a subform (frmHost). I am using
the subform to display any one of several forms, selected by using a command
button which sets the form to be displayed as the SourceObject for the
subform. This works fine.

One of the forms to be displayed (frmToDo) is a continuous form with several
fields. Using command buttons, the user can select which field to sort the
data on. I want to preview and print the data from this form, sorted in the
same way as the user has selected for the form. I identify the command
button pressed by assigning a value to a variable (ReportSelect As Integer).
The value of ReportSelect assigned to an invisible textbox (txtRS), to be
picked up by the report.

When I tried to produce and run a report, it became evident that the sorting
of the data would have to be done before frmToDo processed the line:

DoCmd.OpenReport "rptToDo", acViewPreview

So I added code to the Report Open event, to do the sorting. I began by
picking up the value of txtRS from frmToDo, and then used a Select Case
statement to decide how to sort.

My problem is this: When I work only with frmToDo, and rptToDo, I use this
code to pick up the value of txtRS:

ReportSelect = Forms!frmToDo.txtRS,

and it all works beautifully. But when I take one step back and try to run
it from frmMain, I cannot get the syntax correct. At present I am looking
at the line:

ReportSelect = Forms![frmMain].[frmHost].frmToDo.txtRS

Which produces an error message 'Object doesn't support this property or
method'. I have tried removing [frmToDo] and get the same error message.

Can someone put me right on this please
.
Leonard Priestley

Leonard,

Referring to controls on subforms is very tricky.
According to the examples on this site:

http://mvps.org/access/forms/frm0031.htm

the syntax should be:

Forms!Mainform!Subform1.Form!ControlName

Using your form names it would look like:

ReportSelect = Forms![frmMain]![frmHost].Form!txtRS


Note: you should use the subform control name on the main form, not the
name of the form displayed in the subform control.

HTH
 
Back
Top