I am using Access97.
I have a table with a field called Address. Sample data for that field is: 123 Main Street, 852 L Street, 456 Green St., 55 Maine St., etc.
I have a continuous form based on the table and I want to make a button that lets the user search for similar addresses. So if he clicks on the 123 Main Street record, then clicks my Search command button, I want the form to filter for all similar addresses and display, for example, 55 Maine St, 98 Main Street, 32 Mane St., etc.
I have it working to a degree. This is what I have done. I was just wondering if there is a better way to do it that is more accurate since my results are not exactly what I want:
Form.FilterOn = True
'txtAddress looks for the first blank space in the Address string and takes everything
'to the right of it. So 1234 Main Street would be Main Street.
txtAddress = Mid([Address], (InStr(1, [Address], " "
+ 1))
'txtLength calculates the length of txtAddress, divides it in half, adds 2 and
'rounds the value so it's a whole number. In the Main Street example, txtLength would
'be the value 7. (Main Street has 11 characters, divided in half would be 5.5, add
'2 would be 7.5, and round to 7).
txtLength = Int(Len(txtAddress) / 2) + 2
'txtAddressPortion starts from txtAddress and takes txtLength number of charaters.
'in the Main Street example, the txtAddressPortion would be Main St.
txtAddressPortion = Left([txtAddress], [txtLength])
strFilter = “Address like " & "'" & "*" & txtAddressPortion & "*" & "'"
form.filter=strFilter
End Sub
txtLength is just an arbitrary calculation I decided on. (Cut the length in half and add 2).
My method works to a degree, but, in the 123 Main Street example above, my method unfortunately would NOT include 55 Maine St and 32 Mane St., etc.
Also, if the address was 852 L Street, my formula is searching for the string ‘L Stre’. Therefore, it would return a value of 355 Capitol Street which would be incorrect.
Is there a more accurate way to do what I am trying to do? I see lots of web pages with Search buttons and they work well.
Thanks,
Ruth
I have a table with a field called Address. Sample data for that field is: 123 Main Street, 852 L Street, 456 Green St., 55 Maine St., etc.
I have a continuous form based on the table and I want to make a button that lets the user search for similar addresses. So if he clicks on the 123 Main Street record, then clicks my Search command button, I want the form to filter for all similar addresses and display, for example, 55 Maine St, 98 Main Street, 32 Mane St., etc.
I have it working to a degree. This is what I have done. I was just wondering if there is a better way to do it that is more accurate since my results are not exactly what I want:
Form.FilterOn = True
'txtAddress looks for the first blank space in the Address string and takes everything
'to the right of it. So 1234 Main Street would be Main Street.
txtAddress = Mid([Address], (InStr(1, [Address], " "
'txtLength calculates the length of txtAddress, divides it in half, adds 2 and
'rounds the value so it's a whole number. In the Main Street example, txtLength would
'be the value 7. (Main Street has 11 characters, divided in half would be 5.5, add
'2 would be 7.5, and round to 7).
txtLength = Int(Len(txtAddress) / 2) + 2
'txtAddressPortion starts from txtAddress and takes txtLength number of charaters.
'in the Main Street example, the txtAddressPortion would be Main St.
txtAddressPortion = Left([txtAddress], [txtLength])
strFilter = “Address like " & "'" & "*" & txtAddressPortion & "*" & "'"
form.filter=strFilter
End Sub
txtLength is just an arbitrary calculation I decided on. (Cut the length in half and add 2).
My method works to a degree, but, in the 123 Main Street example above, my method unfortunately would NOT include 55 Maine St and 32 Mane St., etc.
Also, if the address was 852 L Street, my formula is searching for the string ‘L Stre’. Therefore, it would return a value of 355 Capitol Street which would be incorrect.
Is there a more accurate way to do what I am trying to do? I see lots of web pages with Search buttons and they work well.
Thanks,
Ruth