Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Go to Top of Page after Item Selected in List Box

Status
Not open for further replies.

alexbel

Technical User
Jun 27, 2004
77
0
0
US
Hi,

I have a form that has a list box and multiple other fields. When I click to select an item from the list box, it always scrolls to the bottom of the form.

I was wondering if it is possible to scroll it back to the top of the form after an item has been selected from the list box.


Thank you
 
Can you please post the code of the event procedures of the ListBox ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Code:
Private Sub ListBox1_AfterUpdate()


    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[Item ID] = " & str(Nz(Me![ListBox1], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    
Dim l As Long, X As Long, a$
    Dim Strg As String
    Dim StrgArray() As String
    Dim Source As String
    
    Me.Text152 = ""
    Source = Trim(Me.Text150): X = 0
    For l = 1 To Len(Source)
        a$ = Mid$(Source, l, 1)
        If a$ = Chr$(10) Then GoTo Cont1
        If a$ = Chr$(13) Then
           ReDim Preserve StrgArray(X)
           StrgArray(X) = Strg
           X = X + 1
           Strg = "": a$ = ""
           GoTo Cont1
        End If
        Strg = Strg & a$
Cont1:
    Next l
    If Strg <> "" Then
       ReDim Preserve StrgArray(X)
       StrgArray(X) = Strg
       Strg = "": a$ = ""
    End If


    Dim j As Long, Hit As Boolean, k As Integer
    Dim StrgArrayTmp() As String, Hit2 As Integer
    k = 0
    For i = 0 To UBound(StrgArray)
        a$ = StrgArray(i)
        On Error Resume Next
        For j = 0 To UBound(StrgArrayTmp)
           If Err <> 0 Then GoTo ByPass
           If a$ = Left$(StrgArrayTmp(j), Len(a$)) Then Hit = True: Exit For
        Next j
        If Err <> 0 Then Err = 0
        On Error GoTo 0
ByPass:
        If Hit = True Then
           Hit = False
           a$ = ""
             GoTo Cont2
        End If
        
        For X = 0 To UBound(StrgArray)
           If a$ = StrgArray(X) Then Hit2 = Hit2 + 1
        Next X
        ReDim Preserve StrgArrayTmp(k)
        StrgArrayTmp(k) = a$ & "(" & Hit2 & ")" & vbNewLine
        k = k + 1: Hit2 = 0
Cont2:
    Next i
    
    On Error Resume Next
    For i = 0 To UBound(StrgArrayTmp)
       Me.Text152 = Me.Text152 & StrgArrayTmp(i)
    Next i
    

    Erase StrgArray, StrgArrayTmp
    
End Sub

Hope this helps!

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top