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


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

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

     
    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)

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

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