Unable to Reference a Subforms Properties/Controls

Discussion in 'Access VBA Modules' started by David C. Holley, May 31, 2010.

  1. 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, May 31, 2010
    #1
    1. Advertisements

  2. David C. Holley

    Dirk Goldgar Guest

    "David C. Holley" <David.C.Holley> wrote in message
    news:%23%...
    > 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)
     
    Dirk Goldgar, May 31, 2010
    #2
    1. Advertisements

  3. Yep, that's a standard thing that I do to keep life easy.

    "Dirk Goldgar" <> wrote in message
    news:...
    > "David C. Holley" <David.C.Holley> wrote in message
    > news:%23%...
    >> 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)
    >
     
    David C. Holley, Jun 1, 2010
    #3
  4. David C. Holley

    Dirk Goldgar Guest

    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" <David.C.Holley> wrote in message
    news:%...
    > Yep, that's a standard thing that I do to keep life easy.
    >
    > "Dirk Goldgar" <> wrote in message
    > news:...
    >> "David C. Holley" <David.C.Holley> wrote in message
    >> news:%23%...
    >>> 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)
    >>

    >
    >
     
    Dirk Goldgar, Jun 2, 2010
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. brian

    Reference Controls

    brian, Aug 8, 2003, in forum: Access VBA Modules
    Replies:
    1
    Views:
    106
    Marshall Barton
    Aug 8, 2003
  2. George

    Unable to save Database Properties

    George, Nov 12, 2003, in forum: Access VBA Modules
    Replies:
    1
    Views:
    101
  3. Alp Bekisoglu

    Database Properties Type name reference?

    Alp Bekisoglu, Apr 29, 2004, in forum: Access VBA Modules
    Replies:
    4
    Views:
    213
    Alp Bekisoglu
    Apr 29, 2004
  4. john431

    navigating controls in control tabs/subforms

    john431, Oct 23, 2007, in forum: Access VBA Modules
    Replies:
    2
    Views:
    102
    john431
    Oct 23, 2007
  5. jpang
    Replies:
    11
    Views:
    240
    DaveT
    Aug 27, 2008
  6. Abbas
    Replies:
    0
    Views:
    95
    Abbas
    Sep 30, 2008
  7. M_Walker
    Replies:
    2
    Views:
    256
    M_Walker
    Sep 13, 2009
  8. Wyze

    Reference PivotChart view properties?

    Wyze, Mar 24, 2010, in forum: Access VBA Modules
    Replies:
    6
    Views:
    247
Loading...