Let me explain what I understand your problem is:
You want to navigate to unique records each time you click a next button. That is move to the next unique SSN Number as per the example provided. This is what I have done:
I have a table with the Following Fields:
ID (PK) (Autonumber)
SSN (Number)
LastName (Text)
PhoneNumber (Number)
Example
ID |
SSn |
LastName |
PhoneNumber |
1 |
123456789 |
Ashok |
5097863736 |
2 |
123456789 |
Ashok |
6572527257 |
3 |
897262562 |
Kumar |
6572357373 |
4 |
897262562 |
Kumar |
9897867298 |
5 |
897262569 |
Majumdar |
9007897997 |
This is an extract from my table. When your form opens you will looking at Entry with ID:1 SSn:12345678 LastName:Ashok PhoneNumber:5097863 and you want to jump to Entry ID:3 SSn:89726562 LastName:Kumar PhoneNumber:6572357373
The Code:
Code:
Dim rst As DAO.Recordset
Dim strSQL As String
Dim myRecordSource As String
Dim intMyID As String
strSQL = "Select * From Table1 Where ID>" & Me.ID
Set rst = CurrentDb.OpenRecordset(strSQL)
Do While Not rst.EOF
If rst!SSn <> Me.SSn Then
intMyID = rst!ID
Exit Do
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
myRecordSource = "Select * From Table1 Where ID=" & intMyID
Me.RecordSource = myRecordSource
Me.Requery
End Sub
What does the code do:
1) Opens a recordset selects all records with ID number more than the first record displayed in the form.
2) Loops through the records
3) Loop stops when encounters an entry with a SSN number <> equal to the SSN number displayed in the record.
4) Assigns the ID value to the Variable intMyID
5) Use the intMyID to filter the next record.
6) Make myRecordSource the RecordSource of the form.
Note: You will need to change the recordsource of the form to make it show all the records.