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