Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Scrolling record to top of screen. (A2000)

    I don't think this is possible, but I thought I'd give it a try!

    In a continuous subform with more records than can be seen at once, I need to be able to scroll the form so that the current record is at the top of the subform.

    I have a textbox on the mainform in which the user can start typing a name, and as the user types, the subform jumps to the first record which starts with the letters entered so far. However, as the subform "jumps-down" to the next record, it displays it at the bottom of the subform. I'd like to display it at the top of the subform.

    As I see it, the big problem is determining where on the screen the current record is. That is, it may already be at the top of the screen, somewhere in the middle, or at the bottom. I think I can correctly position it if I knew where it was to start, but I don't think such a property exists. Does it?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Scrolling record to top of screen. (A2000)

    I don't think there is a completely satisfactory solution, but the following comes near. It assumes that the text box is named txtSearch, the subform as a control on the main form is named SubForm and that the field in which you search is named FieldName. The code uses DAO, but it could be rewritten to use ADO.
    <code>
    Private Sub txtSearch_Change()
    Dim rst As DAO.Recordset
    Dim strWhere As String
    strWhere = "<!t>[FieldName]<!/t> Like '" & Me.txtSearch.Text & "*'"
    Set rst = Me.<!t>[SubForm]<!/t>.Form.RecordsetClone
    rst.FindFirst strWhere
    If rst.NoMatch Then
    Beep
    Else
    Me.<!t>[SubForm]<!/t>.SetFocus
    RunCommand acCmdRecordsGoToLast
    Me.<!t>[SubForm]<!/t>.Form.Bookmark = rst.Bookmark
    Me.SetFocus
    Me.txtSearch.SetFocus
    Me.txtSearch.SelStart = Len(Me.txtSearch.Text)
    End If
    Set rst = Nothing
    End Sub</code>

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Scrolling record to top of screen. (A2000)

    Hans,

    Thanks. Our code was virtually identical except for that "Runcommand accmdRecordsGoToLast". That may do the trick, as it now has to scroll up, so the found record is at the top of the screen. One other difference in our code is that after set the bookmarks equal, I used the .SetFocus method for one of the controls in the subform to make that record move to the current window.

    In the meantime, I changed the data entry textbox to a listbox that uses as rowsource the same recordset as subform.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •