VScroll does not work with Line added - Run-time error '438'.

Posted on 2006-04-18
Last Modified: 2010-05-01
I have found a code sample out there that lets me add in a vscroll bar so that I can scroll my form.  I'm able to scroll fine, until I added some lines.  The error that I'm getting is as followed:

Run-time error '438': Object doesn't support this property or method.

Here's the code and I use and the line where I"m having issues with.

Option Explicit

Dim oldPos As Integer

Private Sub Form_Load()
Dim iFullFormHeigth As Integer
Dim iDisplayHeight  As Integer

iFullFormHeigth = 12900
iDisplayHeight = 3000

Me.Height = iDisplayHeight

With VScroll1
    .Height = Me.ScaleHeight
    .Min = 0
    .Max = iFullFormHeigth - iDisplayHeight
    .SmallChange = Screen.TwipsPerPixelY * 10
    .LargeChange = .SmallChange
End With

End Sub

Private Sub pScrollForm()
Dim ctl As Control
For Each ctl In Me.Controls
    If Not (TypeOf ctl Is VScrollBar) And _
        Not (TypeOf ctl Is CommandButton) Then
        ctl.Top = ctl.Top + oldPos - VScroll1.Value   -----------------------------------> Here's where it errors out.  Looks like .Top can't be use with line or something.
    End If

oldPos = VScroll1.Value
End Sub

Private Sub VScroll1_Change()
    Call pScrollForm
End Sub

Private Sub VScroll1_Scroll()
    Call pScrollForm
End Sub
Question by:holemania
    LVL 142

    Accepted Solution

    Indeed, the line control does not have Top, left etc, but has x1, x2, y1 and y2 to determine from where to where the line should go.

    Private Sub pScrollForm()
    Dim ctl As Control
    For Each ctl In Me.Controls
        If Not (TypeOf ctl Is VScrollBar) And _
           Not (TypeOf ctl Is CommandButton) Then
               if TypeOf ct is Line then
                  ctl.y1 = ctl.y1 + oldPos - VScroll1.Value  
                  ctl.y2 = ctl.y2 + oldPos - VScroll1.Value  
                  ctl.Top = ctl.Top + oldPos - VScroll1.Value  
               end if
        End If

    Author Comment

    Wow that was quick.  Thanks for the help!!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now