Hi there,
I am extremely new to VBA (As in I found it today). I am using a code and I want to change it. Can the search form bring up anything equal to and like text that is written in the search box of the form.
For context I am creating a userform from a database and want the form to search for specific records and populate the form once the record is found. It's likely people will not write the name of the record in the search box exactly as it is written in the database therefore I want the code to have a like condition (if that's a thing) so that it will pull anything that is equal to or like whatever is written in the search bar.
If anyone can help I would really appreciate it!!!
At the moment this is what I have:-
Private Sub cmdSearch_Click()
Dim x as long
Dim y as long
X= Sheets ("Worksheet").Cells(y,1).value =txtSearch.Text Then
txtID=Sheets ("Worksheet").Cells (y,1).Value
txtName=Sheets ("Worksheet").Cells (y,2).Value
cmbGender=Sheets ("Worksheet").Cells (y,3).Value
txtAddress=Sheets ("Worksheet").Cells (y,4).Value
txtContact=Sheets ("Worksheet").Cells (y,5).Value
End if
Next y
End Sub
I am extremely new to VBA (As in I found it today). I am using a code and I want to change it. Can the search form bring up anything equal to and like text that is written in the search box of the form.
For context I am creating a userform from a database and want the form to search for specific records and populate the form once the record is found. It's likely people will not write the name of the record in the search box exactly as it is written in the database therefore I want the code to have a like condition (if that's a thing) so that it will pull anything that is equal to or like whatever is written in the search bar.
If anyone can help I would really appreciate it!!!
At the moment this is what I have:-
Private Sub cmdSearch_Click()
Dim x as long
Dim y as long
X= Sheets ("Worksheet").Cells(y,1).value =txtSearch.Text Then
txtID=Sheets ("Worksheet").Cells (y,1).Value
txtName=Sheets ("Worksheet").Cells (y,2).Value
cmbGender=Sheets ("Worksheet").Cells (y,3).Value
txtAddress=Sheets ("Worksheet").Cells (y,4).Value
txtContact=Sheets ("Worksheet").Cells (y,5).Value
End if
Next y
End Sub