?
Solved

instr problem in vba

Posted on 2014-09-16
8
Medium Priority
?
350 Views
Last Modified: 2014-09-16
I am using an if statement to determine another process but I have an instr problem:

If (InStr(RstWordGroups.Fields("ConcatenatedUnwantedRemoval").Value, RstAutoRange.Fields("LookFor").Value) <> 0) And (RstWordGroups.Fields("MarqueAlias").Value = RstAutoRange.Fields("Marque").Value) Then

Open in new window



Fields("ConcatenatedUnwantedRemoval").Value = "C 320 AVANTGARDE"
RstAutoRange.Fields("LookFor").Value = "C 32"

How do I change this so that the instr doesnt pick up in this event?

RstAutorange has in it:

"C32"
"C 32"
"C 320"
"C320"

So I only want it to be true if the particular string is in the string
in my example
"C 320 AVANTGARDE" c 32 gets by the instr

I am in vba
0
Comment
Question by:PeterBaileyUk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1000 total points
ID: 40324850
You could look for a "word" with a trailing Space, "C 32 ":

InStr(RstWordGroups.Fields("ConcatenatedUnwantedRemoval").Value, RstAutoRange.Fields("LookFor").Value & " ")

/gustav
0
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 1000 total points
ID: 40324852
Can I cheat? Can I say that you are looking for C32 either at the end of the string, or C32 followed by a space?

If so, then the INSTR then becomes:

InStr(RstWordGroups.Fields("ConcatenatedUnwantedRemoval").Value & " ", RstAutoRange.Fields("LookFor").Value & " ") <> 0)
0
 

Author Comment

by:PeterBaileyUk
ID: 40324861
various clients do this:

"C32"
"C 32"
"C 320"
"C320"

I dont know which part of the string in will be in it might be first or in middle (surrounded by space)

Here is some actual strings for this example:

concatenated
C 320 AVANTGARDE
C 320 AVANTGARDE AUTO
C 320 AVANTGARDE SE
C 320 AVANTGARDE SE CDI
C-CLASS C 320 CDI AVANTGARDE
C-CLASS C 320 CDI AVANTGARDE AUTO
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:PeterBaileyUk
ID: 40324863
i will try the new instr see if it cures
0
 

Author Comment

by:PeterBaileyUk
ID: 40324976
it worked
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 40324977
ok i shared the points hope thats ok
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40324978
That's fine.
0
 
LVL 58
ID: 40324992
Is your problem case sensitivity, the spaces, or both?

Couple of comments:

1. On Case sensitivity, you can:

a. use UCase() to force a string to all upper case, then do the compare.
b. place your check procedure in its own module, then use the Option Compare statement.  There are three settings, Binary, Text, and Database.  Each works differently:

Option Compare Binary results in string comparisons based on a sort order derived from the internal binary representations of the characters. In Microsoft Windows, sort order is determined by the code page. A typical binary sort order is shown in the following example:

A < B < E < Z < a < b < e < z < À < Ê < Ø < à < ê < ø

Option Compare Text results in string comparisons based on a case-insensitive text sort order determined by your system's locale. When the same characters are sorted using Option Compare Text, the following text sort order is produced:

(A=a) < ( À=à) < (B=b) < (E=e) < (Ê=ê) < (Z=z) < (Ø=ø)

Option Compare Database can only be used within Microsoft Access. This results in string comparisons based on the sort order determined by the locale ID of the database where the string comparisons occur.

2. As for the spaces, when I do certain compares, I use a procedure to remove all white space (spaces, tabs, etc) and "collapse" the string so that it's nothing but characters.

  It's easy to write a routine like that using replace().   i.e.

         strText = Replace(strText, " ", "")

  I find compares on collapsed strings more accurate.

HTH,
Jim.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question