Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: InStr problem


Message #1 by "Toni Steinhauer" <toni@t...> on Wed, 23 Jan 2002 14:38:19
Can someone tell me why this statement fails in Access97 when the string 

SID contains CTRLTH232099



    pos = InStr(SID, "B", vbBinaryCompare)



I simply want to know if the string contains a capital B. I keep getting 

a type mismatch error.



Thanks!



Message #2 by "Gregory Serrano" <serranog@m...> on Wed, 23 Jan 2002 16:20:16
Toni,



<< Can someone tell me why this statement fails in Access97 when the 

string SID contains CTRLTH232099



pos = InStr(SID, "B", vbBinaryCompare)



I simply want to know if the string contains a capital B. I keep getting a 

type mismatch error. >>



Did you declare the variable "pos" as a variant?  The function INSTR 

returns a variant.  Try adding this before the statement:



Dim pos as Variant



Greg

Message #3 by "Toni Steinhauer" <toni@t...> on Wed, 23 Jan 2002 19:49:51
> Toni,

> 

> << Can someone tell me why this statement fails in Access97 when the 

> string SID contains CTRLTH232099

> 

> pos = InStr(SID, "B", vbBinaryCompare)

> 

> I simply want to know if the string contains a capital B. I keep 

getting a 

> type mismatch error. >>

> 

> Did you declare the variable "pos" as a variant?  The function INSTR 

> returns a variant.  Try adding this before the statement:

> 

> Dim pos as Variant

> 

> Greg

Greg:



I tried that with no luck. Still got the type mismatch. 



Here is the code that illustrates my real problem:



SID = "CTRL90b90e9s"

pos = InStr(SID, "B")   'look for B

If pos > 0 Then

    pos = InStr(pos, SID, "E")  'look for E

    If pos > 0 Then

        pos = InStr(pos, SID, "S")  'look for S

        If pos > 0 Then             'have a BES format

          MsgBox "SID contains BES"

        End If

    End If

End If





The message box is supposed to show ONLY if the letters BES in upper case 

appear in that order in the string. I had added the vbBinaryCompare to 

try to force it to only accept upper case. In the example above, I get 

the message box to appear even though the letters BES appear in lower 

case in the string. Any ideas?

Message #4 by "Ian Ashton" <ian@c...> on Wed, 23 Jan 2002 20:08:28 -0000

Toni,



If you specify the optional variable [Compare], you also need to specify the

optional variable [Start]



The following works.



	lngPos = InStr(1, strSID, "B", vbBinaryCompare)



(InStr returns a Variant of type Long. I other words lngPos should be

dimensioned as a long).



Ian Ashton







-----Original Message-----

From: Toni Steinhauer [mailto:toni@t...]

Sent: Wednesday, January 23, 2002 2:38 PM

To: Access

Subject: [access] InStr problem





Can someone tell me why this statement fails in Access97 when the string

SID contains CTRLTH232099



    pos = InStr(SID, "B", vbBinaryCompare)



I simply want to know if the string contains a capital B. I keep getting

a type mismatch error.



Thanks!










Message #5 by "Toni Steinhauer" <toni@t...> on Wed, 23 Jan 2002 21:50:38
Ian:



That was the problem! You are a life saver! I have been wrestling with 

this all day!



The second and third test (for E and S) would have been fine, since I did 

specify a starting point. I just omitted the starting point on the test 

for 'B'.



Thanks again!



Toni



> 

> Toni,

> 

> If you specify the optional variable [Compare], you also need to 

specify the

> optional variable [Start]

> 

> The following works.

> 

> 	lngPos = InStr(1, strSID, "B", vbBinaryCompare)

> 

> (InStr returns a Variant of type Long. I other words lngPos should be

> dimensioned as a long).

> 

> Ian Ashton

> 

> 

> 

> -----Original Message-----

> From: Toni Steinhauer [mailto:toni@t...]

> Sent: Wednesday, January 23, 2002 2:38 PM

> To: Access

> Subject: [access] InStr problem

> 

> 

> Can someone tell me why this statement fails in Access97 when the string

> SID contains CTRLTH232099

> 

>     pos = InStr(SID, "B", vbBinaryCompare)

> 

> I simply want to know if the string contains a capital B. I keep getting

> a type mismatch error.

> 

> Thanks!

> 

> 




> 


  Return to Index