InStr returning unexpected result ( Access2013)

AOB

Well-known Member
Joined
Dec 15, 2010
Messages
664
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
Hi everybody,

This has me stumped for some time now...

I'm trying to determine the position of two characters in a string (ASCII 252 or [ü] and ASCII 254 or [þ])

See the below code :

Code:
Sub test()
    Dim strTest As String
    Dim lng252 As Long
    Dim lng254 As Long

    strTest = "Please use this ülinkþ for instructions"

    lng252 = InStr(1, strTest, Chr(252))
    lng254 = InStr(1, strTest, Chr(254))
End Sub

I would imagine that lng252 would evaluate to 17 (it is the 17th character in the test string) and lng254 would evaluate to 22 (it is the 22nd character in the test string)

Instead I'm getting 17 and 12??

Where is it getting 12 from? The 12th character in the string is "t"?

Am I going crazy? :eek:
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Re: InStr returning unexpected result (XL2013)

I get 17 & 22
also on xl2013
 
Upvote 0
Re: InStr returning unexpected result (XL2013)

Okay just copped that the code is actually in Access 2013, not Excel - sorry :oops:

In Excel I get 17 and 22 as well

But in Access, the exact same code gives me 17 and 12

Any ideas?
 
Upvote 0
Re: InStr returning unexpected result (XL2013)

I'll move this to the Access board
 
Upvote 0
Re: InStr returning unexpected result (XL2013)

I get the same result as you if running "Option Compare Database" but get 22 if I remove it
 
  • Like
Reactions: AOB
Upvote 0
Re: InStr returning unexpected result (XL2013)

Specifying the final compare argument should override any Option Compare statements.
 
  • Like
Reactions: AOB
Upvote 0
Re: InStr returning unexpected result (XL2013)

Specifying the final compare argument should override any Option Compare statements.

Should - but doesn't (for me)

Code:
[COLOR=#FF0000]Option Explicit[/COLOR]
[COLOR=#FF0000]Option Compare Database[/COLOR]

Sub test()
    Dim strTest As String
    Dim lng252 As Long
    Dim lng254 As Long

    strTest = "Please use this ülinkþ for instructions"

    lng252 = InStr(1, strTest, Chr(252), [COLOR=#FF0000]vbTextCompare[/COLOR])
    lng254 = InStr(1, strTest, Chr(254), [COLOR=#FF0000]vbTextCompare[/COLOR])
End Sub
 
Upvote 0
Re: InStr returning unexpected result (XL2013)

This works mind...

Code:
[COLOR=#ff0000]Option Explicit[/COLOR]
[COLOR=#ff0000]Option Compare Database[/COLOR]

Sub test()
    Dim strTest As String
    Dim lng252 As Long
    Dim lng254 As Long

    strTest = "Please use this ülinkþ for instructions"

    lng252 = InStr(1, strTest, Chr(252), [COLOR=#ff0000]vbBinaryCompare[/COLOR])
    lng254 = InStr(1, strTest, Chr(254), [COLOR=#ff0000]vb[COLOR=#ff0000]Binary[/COLOR]Compare[/COLOR])
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,618
Messages
6,160,873
Members
451,674
Latest member
TJPsmt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top