Find pound sign ('#') in field string

supmktg

Registered User.
Local time
Today, 09:25
Joined
Mar 25, 2002
Messages
360
In my table, some records include a pound sign character (#) in the FirstLine field, and some don't. I'm trying to determine which records do have a # using the following code:

Code:
Dim rst as DAO.Recordset
Dim str as string
Dim blnPound as Boolean

Set rst = Currentdb.Openrecordset("Table1")

rst.MoveFirst
Do Until rst.EOF
str = rst!FirstLine

If inStr(1,str,"#") > 0 Then
blnPound = True
End if 

rst.MoveNext
Loop

The # character is being treated as a wild card and setting blnPound to True for every record. If I add single quotes ('#'), it doesn't set blnPound to True for any records.

How to I get VBA to recognize the # character as a string character and not a wild card?

Thanks,
Sup

P.S. I'm using Access 2000
 
Last edited:
might be tricky

hash and pound sign are different. maybe JBB is correct, and they share the same char code, depending on the ansi keyboard/character set setting
 
I just wonder why you're not using a query for this or even a DCount() function?
 
Unfortunately, Chr(35) produces the same result as #.

Using Like "*#*" in a query returns all records, the same wildcard result as it does in every other method I have tried.

If I test a string set in my code, it will recognize the #?
This code returns a messagebox with the number 5:

Code:
If InStr(1, "ave # 210", "#") > 0 Then
MsgBox InStr(1, "ave # 210", "#")
End If
 

Users who are viewing this thread

Back
Top Bottom