Hi there,
I have been using the following search code which allows a user to enter either a surname, first name or student id as a search term and click on any matches.
In the event that there are two matches, the only thing to uniquely identify which student this is, is via the student id.
The code has the problem that even though in the code I am saying, display the unique record according to the unique student ID when clicked it displays the first of many records according to the surname.
This is not ideal.
Here is my code:
I have been using the following search code which allows a user to enter either a surname, first name or student id as a search term and click on any matches.
In the event that there are two matches, the only thing to uniquely identify which student this is, is via the student id.
The code has the problem that even though in the code I am saying, display the unique record according to the unique student ID when clicked it displays the first of many records according to the surname.
This is not ideal.
Here is my code:
Code:
Option Compare Database
Private Sub back_Click()
DoCmd.close acForm, "frmStudentSearch", acSaveYes
DoCmd.OpenForm "frm_FrontStudentScreen"
End Sub
Private Sub cmdReset_Click()
On Error GoTo Err_Reset_Click
Me.Search = ""
Me.Search2 = ""
Me.QuickSearch.Requery
Me.QuickSearch.SetFocus
Exit_Reset_Click:
Exit Sub
Err_Reset_Click:
MsgBox Err.Description
Resume Exit_Reset_Click
End Sub
Private Sub Label20_Click()
DoCmd.close acForm, "frmStudentSearch", acSavePrompt
End Sub
Private Sub Label22_Click()
DoCmd.close acForm, "frmStudentSearch", acSavePrompt
End Sub
Private Sub QuickSearch_Click()
DoCmd.OpenForm "frm_student", , , "Surname = '" & Me.QuickSearch & "'"
DoCmd.close acForm, "frmStudentSearch", acSaveYes
DoCmd.close acForm, "frm_FrontStudentScreen", acSaveYes
End Sub
Private Sub Search_Change()
Dim vSearchString As String
If Me.Search.text = "" Then
Me.QuickSearch.RowSource = ""
Else
Me.QuickSearch.RowSource = "student"
End If
vSearchString = Search.text
Search2.Value = vSearchString
Me.QuickSearch.Requery
End Sub
Private Sub QuickSearch_AfterUpdate()
DoCmd.Requery
Me.RecordsetClone.FindFirst [StudentID] = "'" & Me![QuickSearch] & "'"
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
Else
MsgBox "Could not locate [" & Me![QuickSearch] & "]"
End If
End Sub