• A-Z Button – Make Selection Top of View (A97 SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » A-Z Button – Make Selection Top of View (A97 SR2)

    Author
    Topic
    #429184

    I am using buttons A to Z. Clicking on a letter button takes you to the first entry begining with that letter in a form.
    I would like for the first selected record to be at the top of the view. Thank you in advance.

    Private Sub RoloButtons2_AfterUpdate()

    ‘This procedure executed whenever you click on a button in the RoloButtons2 option group.

    Dim FldToSearch, LookFor As String
    ‘Change FldToSearch below to the name of the field in your
    ‘table or query that you want the Rolodex buttons to operate on.
    FldToSearch = “Contractor”

    ‘Make a temporary recordset for searching.
    Dim TempRecSet As Object
    Set TempRecSet = Me.RecordsetClone

    ‘Construct a search string.
    LookFor = “Left([” + FldToSearch + “],1) = ” + Chr(34) + RoloButtons2.Controls.Item(RoloButtons2.Value – 1).Name + Chr(34)

    ‘Find the first matching record.
    TempRecSet.FindFirst LookFor

    ‘If no match found, look for the closest one up.
    If TempRecSet.NoMatch Then
    LookFor = “Left([” + FldToSearch + “],1) >= ” + Chr(34) + RoloButtons2.Controls.Item(RoloButtons2.Value – 1).Name + Chr(34)
    TempRecSet.FindFirst LookFor
    End If

    ‘Go to the matching record (assuming something was found).
    If Not TempRecSet.NoMatch Then
    Me.Bookmark = TempRecSet.Bookmark
    End If

    ‘Pop out the pressed toggle button, clear out the recordset.
    Me.RoloButtons2.Value = 0
    Set TempRecSet = Nothing
    End Sub

    Viewing 0 reply threads
    Author
    Replies
    • #998862

      I assume this is a continuous form. In most cases, the selected record will automatically be scrolled to the top, unless the selected record was already visible. There’s not much you can do about that. Playing with the form’s SelTop property doesn’t help.

      • #998958

        Thank you Hans. Yes it is a continuous form.
        No wonder I was having a hard time.

        • #998986

          I have an idea for a work around.

          How about each time a letter is clicked you first go to fields begginning with the letter A
          and then procede to the one beggining with with the letter you clicked.
          Since there will never be a large number of records in the database there should not be a performance hit.

          How would I go about coding for this?

          • #998999

            The instruction to go to the 1st record is

            RunCommand acCmdRecordsGoToFirst

            • #999003

              I will try it and get back to you later.

            • #999012

              I inserted the following line after (see code in start of thread).

              ‘Find the first matching record.
              TempRecSet.FindFirst LookFor
              DoCmd.RunCommand acCmdRecordsGoToFirst ‘This is the line that I inserted.

              And it works great! Thank you once again Hans.

    Viewing 0 reply threads
    Reply To: A-Z Button – Make Selection Top of View (A97 SR2)

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

    Your information: