Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

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

    Re: A-Z Button - Make Selection Top of View (A97 SR2)

    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.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A-Z Button - Make Selection Top of View (A97 S

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

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A-Z Button - Make Selection Top of View (A97 S

    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?

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

    Re: A-Z Button - Make Selection Top of View (A97 S

    The instruction to go to the 1st record is

    RunCommand acCmdRecordsGoToFirst

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A-Z Button - Make Selection Top of View (A97 S

    I will try it and get back to you later.

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A-Z Button - Make Selection Top of View (A97 S

    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.

Posting Permissions

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