Paul Cooke
Registered User.
- Local time
- Today, 12:42
- Joined
- Oct 12, 2001
- Messages
- 288
Hi guys - hopefully someone can point me in the right direction as to why this is not working please?
I have a table called PatientDetails
I have a form called SearchPatient
In my form I have a textbox called txtName
and
A listbox called lstSearchResults
The rowource for the listbox is
When I open the form all the relevant data is shown in the listbox.
In the on change event of the textbox - txtName I have the following code
But as soon as I type something in the textbox on the form all the data dissapears in the listbox. Even if I delete the values in the textbox the listbox remains empty unless I close and re-open the form.
What I am trying to accomplish is when a letter is typed into the textbox the listbox is filtered down to show only those records relating to the text typed into the textbox.
Hopefully that makes sense and I would be really grateful for any advice or solutions you can offer me as I have spent all day on this now !
Many thanks in advance
Paul
I have a table called PatientDetails
I have a form called SearchPatient
In my form I have a textbox called txtName
and
A listbox called lstSearchResults
The rowource for the listbox is
Code:
SELECT PatientDetails.PatientID, PatientDetails.PatientFirstName, PatientDetails.PatientSurname, PatientDetails.PatientDOB, PatientDetails.HomeAddressPostCode FROM PatientDetails;
When I open the form all the relevant data is shown in the listbox.
In the on change event of the textbox - txtName I have the following code
Code:
Private Sub txtName_Change()
On Error GoTo Err_txtName_Change
Dim strSource As String
strSource = "SELECT PatientFirstName, PatientSurname, PatientDOB, HomeAddressPostCode, PatientID" & _
"FROM PatientDetails " & _
"Where PatientFirstName Like '*" & Me.txtName.Text & "*' " _
& "Or PatientSurname Like '*" & Me.txtName.Text & "*' " _
& "Or PatientDOB Like '*" & Me.txtName.Text & "*' " _
& "Or HomeAddressPostCode Like '*" & Me.txtName.Text & "*' "
Me.lstSearchResults.RowSource = strSource
Exit_txtName_Change: Exit Sub
Err_txtName_Change: MsgBox Err.Number & " " & Err.Description
Resume Err_txtName_Change
End Sub
But as soon as I type something in the textbox on the form all the data dissapears in the listbox. Even if I delete the values in the textbox the listbox remains empty unless I close and re-open the form.
What I am trying to accomplish is when a letter is typed into the textbox the listbox is filtered down to show only those records relating to the text typed into the textbox.
Hopefully that makes sense and I would be really grateful for any advice or solutions you can offer me as I have spent all day on this now !
Many thanks in advance
Paul