Just for kix I added a different type of search to your form.
Its a "search as you type" with a listbox. Double click in the listbox to filter your calling form.
"Search as you type", never cross my mind, I tried it for purpose of diversifying my option on some day, but when I increased the column count to 4, it still only showed the content of Hoten field, what happened here?
Private Sub Text2_Change()
'SELECT [Bangchinh].[Maluutru], [Bangchinh].[Hoten] FROM Bangchinh;
Dim strSql As String
strSql = "SELECT [Bangchinh].[Maluutru], [Bangchinh].[Hoten] FROM Bangchinh where Hoten like ""*" & Me.Text2.Text & "*"""
Me.List0.RowSource = strSql
End Sub
Text2 is where I enter the keyword.
I wish to put Tuoi field = Age field, Ngay field = Date visit field, they are all number, don't know how to fill the code
According to your notes in the DB you were just searching for a client so thats all I included in the SQL. The rowsource is established in code, not in the listbox.
note the following events
Code:
Private Sub Form_Load()
Me.List0.RowSource = "SELECT Bangchinh.Maluutru, Bangchinh.Hoten, Bangphu.Yeucau, Bangchinh.Ketluan, Bangchinh.Tuoi, Bangchinh.Ngaysieuam, " & _
"Bangchinh.Diachi FROM Bangphu INNER JOIN Bangchinh ON Bangphu.Mayeucausieuam = Bangchinh.Mayeucausieuam WHERE Maluutru = 0"
End Sub
Thats just to load a blank record in listbox because I set column heads to yes.
Code:
Private Sub Text2_Change()
Dim strSql As String
strSql = "SELECT Bangchinh.Maluutru, Bangchinh.Hoten, Bangphu.Yeucau, Bangchinh.Ketluan, Bangchinh.Tuoi, Bangchinh.Ngaysieuam, " & _
"Bangchinh.Diachi FROM Bangphu INNER JOIN Bangchinh ON Bangphu.Mayeucausieuam = Bangchinh.Mayeucausieuam " & _
"WHERE [Maluutru] & [Hoten] & [Ngaysieuam] & [Diachi] & [Tuoi] & [Yeucau] Like ""*" & Me.Text2.Text & "*"""
Me.List0.RowSource = strSql
End Sub
This is where the rowsource is set for the listbox
it uses Conditional Format (Ribbon->Format->Conditional Formatting).
on the search form i modified, open in Design View, select all the textboxes on the Detail
section of the form.
Go to ribbon and see the Conditional Formatting.
The search which I found has a text box with the content like "... results were found." That search uses a list box, I see this code: = IIf(ListBoxName.ListCount-1=-1,"0",ListBoxName.ListCount-1) & "results were found."
Can you help me with that on your search db?
According to your notes in the DB you were just searching for a client so thats all I included in the SQL. The rowsource is established in code, not in the listbox.
note the following events
Code:
Private Sub Form_Load()
Me.List0.RowSource = "SELECT Bangchinh.Maluutru, Bangchinh.Hoten, Bangphu.Yeucau, Bangchinh.Ketluan, Bangchinh.Tuoi, Bangchinh.Ngaysieuam, " & _
"Bangchinh.Diachi FROM Bangphu INNER JOIN Bangchinh ON Bangphu.Mayeucausieuam = Bangchinh.Mayeucausieuam WHERE Maluutru = 0"
End Sub
Thats just to load a blank record in listbox because I set column heads to yes.
Code:
Private Sub Text2_Change()
Dim strSql As String
strSql = "SELECT Bangchinh.Maluutru, Bangchinh.Hoten, Bangphu.Yeucau, Bangchinh.Ketluan, Bangchinh.Tuoi, Bangchinh.Ngaysieuam, " & _
"Bangchinh.Diachi FROM Bangphu INNER JOIN Bangchinh ON Bangphu.Mayeucausieuam = Bangchinh.Mayeucausieuam " & _
"WHERE [Maluutru] & [Hoten] & [Ngaysieuam] & [Diachi] & [Tuoi] & [Yeucau] Like ""*" & Me.Text2.Text & "*"""
Me.List0.RowSource = strSql
End Sub
This is where the rowsource is set for the listbox
Which part of the code is "search as you type", can I have it inserted in the search box which @arnelgp modified for me? Or it's just a feature for listbox only?