• Scrolling record to top of screen. (A2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Scrolling record to top of screen. (A2000)

    • This topic has 2 replies, 2 voices, and was last updated 19 years ago.
    Author
    Topic
    #431994

    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?

    Viewing 0 reply threads
    Author
    Replies
    • #1012452

      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.

      Private Sub txtSearch_Change()
      Dim rst As DAO.Recordset
      Dim strWhere As String
      strWhere = "[FieldName] Like '" & Me.txtSearch.Text & "*'"
      Set rst = Me.[SubForm].Form.RecordsetClone
      rst.FindFirst strWhere
      If rst.NoMatch Then
      Beep
      Else
      Me.[SubForm].SetFocus
      RunCommand acCmdRecordsGoToLast
      Me.[SubForm].Form.Bookmark = rst.Bookmark
      Me.SetFocus
      Me.txtSearch.SetFocus
      Me.txtSearch.SelStart = Len(Me.txtSearch.Text)
      End If
      Set rst = Nothing
      End Sub

      • #1012474

        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.

    Viewing 0 reply threads
    Reply To: Scrolling record to top of screen. (A2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: