none
Msaccess error code RRS feed

  • Question

  • Me.LnDetBot.Top = Tp

    On opening the report the above error code comes.

    this error comes from a report having following code.  The db file in original was having only 5 columns whereas I have increased to 15 columns found the above error code.

    The total code is also follows :

    Private Sub ReportHeader_Format(Cancel As Integer, _
                                                FormatCount As Integer)
    On Error GoTo ErrTrap
        Dim rst As DAO.Recordset
        Dim Fnm As String, Lnm As String
        Dim Tp As Long
        ' Vert margin between consequtive fields
        Const Mgn As Long = 30
        
        Set rst = Forms("F_Main")("SF_Sub").Form.RecordsetClone
        If rst.BOF Then
            ' Recorset is empty
            GoTo ExitPoint
        Else
            rst.MoveFirst
        End If
        
        ' Set detail height to a large value so as to
        ' accomodate maximum likely fields
        Me.Detail.Height = 5000
        
        ' Set initial value for top of first field
        Tp = 80
        Do Until rst.EOF
            ' Get field & label names
            Fnm = rst.Fields("FieldName")
            Lnm = "Lb" & Fnm
            
            ' Manipulate position and visibility of fields
            ' and labels, as per the Active status as
            ' selected by the user
            If rst.Fields("Active") = True Then
                Me(Fnm).Visible = True
                Me(Lnm).Visible = True
                
                Me(Fnm).Top = Tp
                Me(Lnm).Top = Tp
                
                Tp = Tp + Me(Fnm).Height + Mgn   ' (A)
            Else
                Me(Fnm).Visible = False
                Me(Lnm).Visible = False
                Me(Fnm).Top = 0
                Me(Lnm).Top = 0
            End If
            
            rst.MoveNext
        Loop
        
        ' Set top position of  bottom line in detail section
        ' Appropriate value has already been computed
        ' as per statement (A)
        Me.LnDetBot.Top = Tp
        
        ' Setting detail height to zero ensures
        ' tight fit over its contents
        Me.Detail.Height = 0
        
    ExitPoint:
        On Error Resume Next
        rst.Close
        Set rst = Nothing
        On Error GoTo 0
        Exit Sub
            
    ErrTrap:
        MsgBox Err.Number & " - " & Err.Description
        Resume ExitPoint
    End Sub

    Sunday, December 24, 2017 9:22 AM

All replies

  • What error are you receiving exactly (number and description please)?

    When the error occurs and you debug, what is the value of Tp?

    Does your VBA compile without errors?


    Daniel Pineault, 2010-2017 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net


    Sunday, December 24, 2017 12:51 PM
  •     Tp = 80
        Do Until rst.EOF
            ' Get field & label names
            Fnm = rst.Fields("FieldName")
            Lnm = "Lb" & Fnm

    Hi BroMariaThomas,

    You loop through a recordset, and for each record you pick only the fields with name "FieldName" and "Active".

    What I suppose is that you want to loop through all the fields in that records. You then need an extra line, such as:

            For Each cur_field In rst.Fields
               Fnm = cur_field.Name
               Lnm = "Lb" & Fnm
               ...

               If cur_field.Name = "Active") ...

               ...

            Next

    Imb.

    Sunday, December 24, 2017 1:28 PM
  • Hi BroMaria,

    Has your issue resolved?

    If it has, I would suggest you mark the helpful reply as answer to close this thread.

    If not, please feel free to let us know.

    Regards,

    Tony


    Help each other

    Wednesday, January 3, 2018 7:42 AM