Unable to Reference a Subforms Properties/Controls

  • Thread starter Thread starter David C. Holley
  • Start date Start date
D

David C. Holley

I'm trying to alter the recordsource of a subform at runtime (something I've
done before) and I'm just not getting why I'm getting an error - "You
entered an expression that has an invalid reference to the property
Form/Report." The code craps out where I've got the asterik. I snooped
around trying to reference the controls and properties of the subform via
the Immediate Window, but no luck. The subform is on tabctl, but its my
understanding that that shouldn't be a problem.

Private Sub Form_Open(Cancel As Integer)

Dim strRecordSource As String

'Massage the recordsource, the criteria for the subform changes based on
its usage
* If Right(Me.subfrmTrailerActivityComments.Form.RecordSource, 1) = ";"
Then
strRecordSource =
Left(Me.subfrmTrailerActivityComments.Form.RecordSource,
Len(Me.subfrmTrailerActivityComments.Form.RecordSource) - 1)
Else
strRecordSource = Me.subfrmTrailerActivityComments.Form.RecordSource
End If

strRecordSource = strRecordSource & "WHERE lngTrailerActivityHeaderId =
me.parent.lngTrailerActivityHeaderId ORDER BY lngCommentId"
Me.subfrmTrailerActivityComments.Form.RecordSource = strRecordSource
Me.subfrmTrailerActivityComments.Form.lstComments.RowSource =
strRecordSource
Me.subfrmTrailerActivityComments.Form.lstComments.Requery
Me.subfrmTrailerActivityComments.Requery

End Sub

?err.Number
2455
?err.Description
You entered an expression that has an invalid reference to the property
Form/Report.
?me.controls("subfrmTrailerActivityComments").name
subfrmTrailerActivityComments
?me.Controls("subfrmTrailerActivityComments").form.controls.count
[Error]
?me.Controls("subfrmTrailerActivityComments").controltype
112
?acSubform
112
?[Forms]![frmTrailerActivity_ByShow]![subfrmTrailerActivityComments].form!lstComments.controltype
[Error]
 
David C. Holley said:
I'm trying to alter the recordsource of a subform at runtime (something
I've done before) and I'm just not getting why I'm getting an error - "You
entered an expression that has an invalid reference to the property
Form/Report." The code craps out where I've got the asterik. I snooped
around trying to reference the controls and properties of the subform via
the Immediate Window, but no luck. The subform is on tabctl, but its my
understanding that that shouldn't be a problem.

Private Sub Form_Open(Cancel As Integer)

Dim strRecordSource As String

'Massage the recordsource, the criteria for the subform changes based
on its usage
* If Right(Me.subfrmTrailerActivityComments.Form.RecordSource, 1) = ";"
Then
strRecordSource =
Left(Me.subfrmTrailerActivityComments.Form.RecordSource,
Len(Me.subfrmTrailerActivityComments.Form.RecordSource) - 1)
Else
strRecordSource =
Me.subfrmTrailerActivityComments.Form.RecordSource
End If

strRecordSource = strRecordSource & "WHERE lngTrailerActivityHeaderId =
me.parent.lngTrailerActivityHeaderId ORDER BY lngCommentId"
Me.subfrmTrailerActivityComments.Form.RecordSource = strRecordSource
Me.subfrmTrailerActivityComments.Form.lstComments.RowSource =
strRecordSource
Me.subfrmTrailerActivityComments.Form.lstComments.Requery
Me.subfrmTrailerActivityComments.Requery

End Sub

?err.Number
2455
?err.Description
You entered an expression that has an invalid reference to the property
Form/Report.
?me.controls("subfrmTrailerActivityComments").name
subfrmTrailerActivityComments
?me.Controls("subfrmTrailerActivityComments").form.controls.count
[Error]
?me.Controls("subfrmTrailerActivityComments").controltype
112
?acSubform
112
?[Forms]![frmTrailerActivity_ByShow]![subfrmTrailerActivityComments].form!lstComments.controltype
[Error]


Does your subform control have its SourceObject property set to the name of
a form? You might add this:

?Me.controls("subfrmTrailerActivityComments").SourceObject

to your debugging logic.
 
Yep, that's a standard thing that I do to keep life easy.

Dirk Goldgar said:
David C. Holley said:
I'm trying to alter the recordsource of a subform at runtime (something
I've done before) and I'm just not getting why I'm getting an error -
"You entered an expression that has an invalid reference to the property
Form/Report." The code craps out where I've got the asterik. I snooped
around trying to reference the controls and properties of the subform via
the Immediate Window, but no luck. The subform is on tabctl, but its my
understanding that that shouldn't be a problem.

Private Sub Form_Open(Cancel As Integer)

Dim strRecordSource As String

'Massage the recordsource, the criteria for the subform changes based
on its usage
* If Right(Me.subfrmTrailerActivityComments.Form.RecordSource, 1) = ";"
Then
strRecordSource =
Left(Me.subfrmTrailerActivityComments.Form.RecordSource,
Len(Me.subfrmTrailerActivityComments.Form.RecordSource) - 1)
Else
strRecordSource =
Me.subfrmTrailerActivityComments.Form.RecordSource
End If

strRecordSource = strRecordSource & "WHERE lngTrailerActivityHeaderId
= me.parent.lngTrailerActivityHeaderId ORDER BY lngCommentId"
Me.subfrmTrailerActivityComments.Form.RecordSource = strRecordSource
Me.subfrmTrailerActivityComments.Form.lstComments.RowSource =
strRecordSource
Me.subfrmTrailerActivityComments.Form.lstComments.Requery
Me.subfrmTrailerActivityComments.Requery

End Sub

?err.Number
2455
?err.Description
You entered an expression that has an invalid reference to the property
Form/Report.
?me.controls("subfrmTrailerActivityComments").name
subfrmTrailerActivityComments
?me.Controls("subfrmTrailerActivityComments").form.controls.count
[Error]
?me.Controls("subfrmTrailerActivityComments").controltype
112
?acSubform
112
?[Forms]![frmTrailerActivity_ByShow]![subfrmTrailerActivityComments].form!lstComments.controltype
[Error]


Does your subform control have its SourceObject property set to the name
of a form? You might add this:

?Me.controls("subfrmTrailerActivityComments").SourceObject

to your debugging logic.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
Then the only thing I can think of is that the form name specified as your
Source Object may be incorrect. I don't see any other reason for the
problem, and your code looks okay to me.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

David C. Holley said:
Yep, that's a standard thing that I do to keep life easy.

Dirk Goldgar said:
David C. Holley said:
I'm trying to alter the recordsource of a subform at runtime (something
I've done before) and I'm just not getting why I'm getting an error -
"You entered an expression that has an invalid reference to the property
Form/Report." The code craps out where I've got the asterik. I snooped
around trying to reference the controls and properties of the subform
via the Immediate Window, but no luck. The subform is on tabctl, but its
my understanding that that shouldn't be a problem.

Private Sub Form_Open(Cancel As Integer)

Dim strRecordSource As String

'Massage the recordsource, the criteria for the subform changes based
on its usage
* If Right(Me.subfrmTrailerActivityComments.Form.RecordSource, 1) =
";" Then
strRecordSource =
Left(Me.subfrmTrailerActivityComments.Form.RecordSource,
Len(Me.subfrmTrailerActivityComments.Form.RecordSource) - 1)
Else
strRecordSource =
Me.subfrmTrailerActivityComments.Form.RecordSource
End If

strRecordSource = strRecordSource & "WHERE lngTrailerActivityHeaderId
= me.parent.lngTrailerActivityHeaderId ORDER BY lngCommentId"
Me.subfrmTrailerActivityComments.Form.RecordSource = strRecordSource
Me.subfrmTrailerActivityComments.Form.lstComments.RowSource =
strRecordSource
Me.subfrmTrailerActivityComments.Form.lstComments.Requery
Me.subfrmTrailerActivityComments.Requery

End Sub

?err.Number
2455
?err.Description
You entered an expression that has an invalid reference to the property
Form/Report.
?me.controls("subfrmTrailerActivityComments").name
subfrmTrailerActivityComments
?me.Controls("subfrmTrailerActivityComments").form.controls.count
[Error]
?me.Controls("subfrmTrailerActivityComments").controltype
112
?acSubform
112
?[Forms]![frmTrailerActivity_ByShow]![subfrmTrailerActivityComments].form!lstComments.controltype
[Error]


Does your subform control have its SourceObject property set to the name
of a form? You might add this:

?Me.controls("subfrmTrailerActivityComments").SourceObject

to your debugging logic.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
Back
Top