We help IT Professionals succeed at work.
Get Started

Access VBA - Search field for string where string does not have number immediately before or after

Scamquist
Scamquist asked
on
1,073 Views
Last Modified: 2014-05-09
I have some VBA code in Access to look in a string field and return records that contain another string.

For example:

SearchField may be:

BB13118000022,SUPPORT PROFILE TURN CAP


and I want to return the record if the string (strfind) is 3118000022

The statement below returns the proper records

strcriteria = "SearchField  LIKE '" & "*" & strfind & "*" & "'"


However, if the character immediately before or after strfind is a number, I do not want to return that record.

I tried
'remove records with number before strfind      
  strcriteria = "SearchField  NOT LIKE '" & # & "*" & strfind & "*" & "'"
'remove remainin records with number after strfind
  strcriteria = "strcriteria  NOT LIKE '" & "*" & strfind & "*" & # & "'"  
'remaining records, return with strfind  
  strcriteria = "strcriteria  LIKE '" & "*" & strfind & "*" & "'"

it failed on the # symbol
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE