FindRecord and #

T

The Seversons

I am attempting to use the FindRecord method to locate a specific record on
a form. The data I am searching for contains special characters like the #
symbol. The FindRecord search does not work with these symbols. Is their a
way to work around this and still use FindRecord?

Sean M. Severson
 
D

Dirk Goldgar

The Seversons said:
I am attempting to use the FindRecord method to locate a specific
record on a form. The data I am searching for contains special
characters like the # symbol. The FindRecord search does not work
with these symbols. Is their a way to work around this and still use
FindRecord?

Sean M. Severson

I think the problem is that this is among the wild-card characters that
are honored by the FindRecord method. If you know you are going to be
searching for one of these characters, you can wrap it in square
brackets to make it act as a literal character, like this:

DoCmd.FindRecord "Record [#]1", acAnywhere

If you aren't sure, conceivably you could use the Replace function to
replace occurrences of the special characters with themselves wrapped in
brackets; e.g.,

strFindWhat = "Record #1"
strFindWhat = Replace(strFindWhat, "#", "[#]")
DoCmd.FindRecord strFindWhat, acAnywhere

You might have to replace several different characters with their
bracket-wrapped equivalents.

If you're searching for a whole-field match, it may be easier to use a
recordsetclone search to find the desired record instead:

With Me.RecordsetClone
.FindFirst "MyField = 'Record #1'"
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top