Unable to Reference a Subforms Properties/Controls

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]
 
D

Dirk Goldgar

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.
 
D

David C. Holley

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)
 
D

Dirk Goldgar

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)
 

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