Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error 5 "Invalid Code or Procedure" when using string functions

24 views
Skip to first unread message

Greg (codepug@gmail.com)

unread,
May 29, 2012, 6:49:05 PM5/29/12
to
I'm getting Error 5 "Invalid Code or Procedure" when I execute the
following line of code:
If (Left((strCutAddress), InStr(1, (strCutAddress), " ") - 1))
= "West " Then

I am looping through my data table and populating strCutAddress with
the value from a field in the table
Everything works fine for the first 3 fields, and when I reach the 4th
field I get the error message.

Any Ideas?

Bob Quintal

unread,
May 29, 2012, 7:11:46 PM5/29/12
to
"Greg (cod...@gmail.com)" <cod...@gmail.com> wrote in
news:bfb56e18-6210-412e...@e18g2000yqc.googlegroups.co
m:
There is no space in the fourth field. Access gets upset when asked to
do a left(something, -1)

Why bother with the instr() function here at all,
If Left(strCutAddress,5) = "West " Then
will work.

--
Bob Q.
PA is y I've altered my address.

Douglas J Steele

unread,
May 29, 2012, 8:17:02 PM5/29/12
to
Is it possble that the content of strCutAddress for that row didn't have a
space in it, so that InStr would have returned 0, and so the Left function
tried to take the left-most -1 characters?

wrote in message
news:bfb56e18-6210-412e...@e18g2000yqc.googlegroups.com...

Bob Barrows

unread,
May 29, 2012, 8:54:33 PM5/29/12
to
Show us the data? Both the ones that work (and their results) and the one
that caused the error ... unless Bob Quintal is correct about your problem,
of course


Greg (codepug@gmail.com)

unread,
May 31, 2012, 2:42:21 PM5/31/12
to
Thanks Bob

This worked just fine for me. Otherwise, I could not find any problem
with the data
I was pulling from, and just no time to investigate why this was
failing. Thanks Again.
0 new messages