Eric the Viking
Registered User.
- Local time
- Today, 13:07
- Joined
- Sep 20, 2012
- Messages
- 70
I have a table of names and unique ID numbers which I want to search from an unbound textbox on a form and return the result to a listbox.
I can do it using name but would like to use either name or ID to return either a list of people with the same name or a person with a particular ID number. The code is in the afterupdate event:
Private Sub TextSurname_AfterUpdate()
On Error Resume Next
ListPts.RowSource = "Select tblpatients.PatientNumber,tblpatients.Surname,tblpatients.Firstname1,tblpatients.DateofBirth,tblpatients.NHSnumber " & _
"FROM tblpatients " & _
"WHERE tblpatients.Surname = '" & TextSurname.Value & "' " & _
"ORDER BY tblpatients.Firstname1;"
Dim getListPtsCount As Integer
Dim setHeight As Integer
getListPtsCount = Me.ListPts.ListCount
setHeight = 240
Me.ListPts.Height = getListPtsCount * setHeight
End Sub
The user can then click a record in the listbox which opens the full record in a new form and at the same time clears the contents of the textbox and listbox ready for a new search.
I am new to VBA so forgive me if the above looks clunky but it does seem to work. Any advice on refinements gratefully received.
Cheers
Eric
I can do it using name but would like to use either name or ID to return either a list of people with the same name or a person with a particular ID number. The code is in the afterupdate event:
Private Sub TextSurname_AfterUpdate()
On Error Resume Next
ListPts.RowSource = "Select tblpatients.PatientNumber,tblpatients.Surname,tblpatients.Firstname1,tblpatients.DateofBirth,tblpatients.NHSnumber " & _
"FROM tblpatients " & _
"WHERE tblpatients.Surname = '" & TextSurname.Value & "' " & _
"ORDER BY tblpatients.Firstname1;"
Dim getListPtsCount As Integer
Dim setHeight As Integer
getListPtsCount = Me.ListPts.ListCount
setHeight = 240
Me.ListPts.Height = getListPtsCount * setHeight
End Sub
The user can then click a record in the listbox which opens the full record in a new form and at the same time clears the contents of the textbox and listbox ready for a new search.
I am new to VBA so forgive me if the above looks clunky but it does seem to work. Any advice on refinements gratefully received.
Cheers
Eric