Unanswered: Help with code to search for text string please.
I have an access database in which one form is based on tblCustomer and shows Customer Name and Address details. To find any required record the user can input the required name into a text box, click a command button and using the code shown below, find the required record.
DoCmd.FindRecord txtFindName, , , , , , False
Other code allows for multiple finds and fwd and back buttons allow for these to be viewed. This all works ok.
However, this method requires the complete Name to be inputted. I want to change this so the user can input, say just the first few letters of the name, click search and the code will select all records with a name starting with those letters. I have tried adding acStart to the code below as a parameter but with no success. I know I can do this with a parameter query but I want to use vba as a development to achieve this. I would be grateful to know how to go about making this change to the search process e.g. can I simply change the DoCmd line with another parameter? With thanks for any help you can give me.
Thanks for your help Teddy. I have dealt with the fact that FindRecord will only find one record by using it in a Do Loop Until. I count the total number of finds and then have some code with back and forward buttons to go back to review all the finds. This works for me since I will only have 3 or 4 found records to review. What I havn't been able to do is to get wildcard characters to work in the textbox I use (txtFindName) for the search argument in conjuction with the FindRecord command. However, I also want to make the search work after inputting just a few characters i.e. if I input smi and click search I will identify all names beginning smi like smith and smithers. I will go and have another look at wildcards again now and have another go. Again thanks for your input.
Thank you for your input which I have tried to use in this prob. After trying for ages to fix this prob. I discovered that my search code was working ok even when I used wildcards, but the error coding seems to be the prob. The section of the code is shown below. When ever I use a wildcard in txtFindName this section of the code never recognises it and it throws up a Failed to find Msg. when it should not.
If I REM out this part of the code everything else works with or without the use of wildcards and I can find any record.
I would be very grateful for any help to show me how I can fix the CustomerSurname <> txtFindName line in here.
'no matching records
If CustomerSurname <> txtFindName Then
MsgBox "Failed to find any matching records.", _
0, "Search Failed"