dbTalk Databases Forums  

FindRecord

comp.databases.ms-access comp.databases.ms-access


Discuss FindRecord in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
imb
 
Posts: n/a

Default FindRecord - 12-04-2010 , 08:07 AM






Hi,

When I use

DoCmd.FindRecord "#", acStart

in a form, the form shows a record that starts with a number.
But I want to go to a record that starts with "#". How can I do that?

Thanks, Imb.

Reply With Quote
  #2  
Old   
Marshall Barton
 
Posts: n/a

Default Re: FindRecord - 12-04-2010 , 02:19 PM






imb wrote:
Quote:
When I use

DoCmd.FindRecord "#", acStart

in a form, the form shows a record that starts with a number.
But I want to go to a record that starts with "#". How can I do that?

Try using:
DoCmd.FindRecord "[#]", acStart

Search Help for Wildcard Characters to see why.

--
Marsh

Reply With Quote
  #3  
Old   
imb
 
Posts: n/a

Default Re: FindRecord - 12-04-2010 , 03:09 PM



Thank you, Marsh, for your answer.


Yes, it works, but this is not the way I'm looking for.
I was hoping that there was some argument that can be set to eliminate
the wildcharacter behaviour, and search for text as it is typed in.

In my application the user types in a search text in some kind of
command line, and at the same time the form displays the matching
record (or indicates that no record was found).
It is a little unhandy if a user must surround the # bij square
brackets, for just the #-character.

Imb.



On Dec 4, 9:19*pm, Marshall Barton <marshbar... (AT) wowway (DOT) com> wrote:
Quote:
imb wrote:
When I use

* DoCmd.FindRecord "#", acStart

in a form, the form shows a record that starts with a number.
But I want to go to a record that starts with "#". How can I do that?

Try using:
* *DoCmd.FindRecord "[#]", acStart

Search Help for Wildcard Characters to see why.

--
Marsh

Reply With Quote
  #4  
Old   
Marshall Barton
 
Posts: n/a

Default Re: FindRecord - 12-04-2010 , 04:33 PM



FindRecord is not that versatile. Try something more like:

With Me.RecordsetClone
.FindFirst "Left([the field], " _
& Len(Me.[the text box].Text) & ") = """ _
& Replace(Me.[the text box].Text, """", """""") _
& """"
If Not .NoMatch Then Me.Boolmark = .Bookmark
End With
--
Marsh


imb wrote:
Quote:
Yes, it works, but this is not the way I'm looking for.
I was hoping that there was some argument that can be set to eliminate
the wildcharacter behaviour, and search for text as it is typed in.

In my application the user types in a search text in some kind of
command line, and at the same time the form displays the matching
record (or indicates that no record was found).
It is a little unhandy if a user must surround the # bij square
brackets, for just the #-character.


On Dec 4, 9:19*pm, Marshall Barton wrote:
imb wrote:
When I use

* DoCmd.FindRecord "#", acStart

in a form, the form shows a record that starts with a number.
But I want to go to a record that starts with "#". How can I do that?

Try using:
* *DoCmd.FindRecord "[#]", acStart

Search Help for Wildcard Characters to see why.

Reply With Quote
  #5  
Old   
imb
 
Posts: n/a

Default Re: FindRecord - 12-04-2010 , 05:39 PM



Hi Marsh,

Thank you for your response.

Whereas I use DoCmd.FindRecord for unsorted fields, I use
already .RecordsetClone.FindFirst for sorted fields.
But also here, FindFirst uses # as a wildcard character.

Converting with so many quotes makes the logic untransparant, so
probably I will not use that.
I think more in using FindRecord or FindFirst in those cases that the
search-for value contains no wildcard characters, whereas with
wildcard characters I will loop through the RecordsetClone set.
A complexing factor is that I want to use the "*" as wildcard
character, but not all the rest.

By the way, using A2003, I could not find any help on Wildcard
characters, nor did FindRecord nor Findfirst mention this.

Imb.




On Dec 4, 11:33*pm, Marshall Barton <marshbar... (AT) wowway (DOT) com> wrote:
Quote:
FindRecord is not that versatile. *Try something more like:

With Me.RecordsetClone
* *.FindFirst *"Left([the field], " _
* * * * * *& Len(Me.[the text box].Text) *& ") = """ _
* * * * * *& Replace(Me.[the text box].Text, """", """""") _
* * * * * *& """"
* *If Not .NoMatch Then Me.Boolmark = .Bookmark
End With
--
Marsh



imb wrote:
Yes, it works, but this is not the way I'm looking for.
I was hoping that there was some argument that can be set to eliminate
the wildcharacter behaviour, and search for text as it is typed in.

In my application the user types in a search text in some kind of
command line, and at the same time the form displays the matching
record (or indicates that no record was found).
It is a little unhandy if a user must surround the # bij square
brackets, for just the #-character.

On Dec 4, 9:19 pm, Marshall Barton wrote:
imb wrote:
When I use

DoCmd.FindRecord "#", acStart

in a form, the form shows a record that starts with a number.
But I want to go to a record that starts with "#". How can I do that?

Try using:
DoCmd.FindRecord "[#]", acStart

Search Help for Wildcard Characters to see why.- Hide quoted text -

- Show quoted text -

Reply With Quote
  #6  
Old   
Marshall Barton
 
Posts: n/a

Default Re: FindRecord - 12-04-2010 , 06:32 PM



imb wrote:
Quote:
Whereas I use DoCmd.FindRecord for unsorted fields, I use
already .RecordsetClone.FindFirst for sorted fields.
I don't see how sorting the records should determine which
technique is used.

Quote:
But also here, FindFirst uses # as a wildcard character.
FindFirst only uses wildcards when you use the Like
operator. I used Left and = to avoid using a wildcard as
you requested.

Quote:
Converting with so many quotes makes the logic untransparant, so
probably I will not use that.
There are ways to write that using a constant instead of so
many quotes:

Const QT As string = """"
*.FindFirst *"Left([the field], " _
* * * *& Len(Me.[the text box].Text) *& ") = " & QT _
* * * *& Replace(Me.[the text box].Text, QT, QT & QT) & QT

Quote:
I think more in using FindRecord or FindFirst in those cases that the
search-for value contains no wildcard characters, whereas with
wildcard characters I will loop through the RecordsetClone set.
That doesn't make sense to me. You do not need to check for
wildcards in the search string. You can just add the [ ] to
hide them using the Replace function. For example:
.FindFirst "[the field] Like '*" & Replace(Me.[the text
box].Text, "#", "[#]") & "*' "

If you do not want users to be able to use any wildcards,
but want all their characters to be taken literally, you can
neutralize all wildcards with code along these lines:

Const Wildcards As String = "[*#?" ' [ must be first
Dim Search As String, k As Integer
Search = Me.[the text box].Text
For k = 1 To Len(Wildcards)
Search = Replace(Search, Mid(Wildcards,k,1), "[" &
Mid(Wildcards,k,1) & "]")
Next k
.FindFirst "[the field] Like ""*" & Search & "*"" "
. . .

Looping through a recordset is an order of magnitude slower
then FindFirst.

Quote:
A complexing factor is that I want to use the "*" as wildcard
character, but not all the rest.
The above allows you to use * to search anywhere in the
field.

Quote:
By the way, using A2003, I could not find any help on Wildcard
characters, nor did FindRecord nor Findfirst mention this.
Maybe you looked in online help?? I found it in both Access
Offline Help and in VBA Help.
--
Marsh


Quote:
On Dec 4, 11:33*pm, Marshall Barton wrote:
FindRecord is not that versatile. *Try something more like:

With Me.RecordsetClone
* *.FindFirst *"Left([the field], " _
* * * * * *& Len(Me.[the text box].Text) *& ") = """ _
* * * * * *& Replace(Me.[the text box].Text, """", """""") _
* * * * * *& """"
* *If Not .NoMatch Then Me.Boolmark = .Bookmark
End With
--
Marsh



imb wrote:
Yes, it works, but this is not the way I'm looking for.
I was hoping that there was some argument that can be set to eliminate
the wildcharacter behaviour, and search for text as it is typed in.

In my application the user types in a search text in some kind of
command line, and at the same time the form displays the matching
record (or indicates that no record was found).
It is a little unhandy if a user must surround the # bij square
brackets, for just the #-character.

On Dec 4, 9:19 pm, Marshall Barton wrote:
imb wrote:
When I use

DoCmd.FindRecord "#", acStart

in a form, the form shows a record that starts with a number.
But I want to go to a record that starts with "#". How can I do that?

Try using:
DoCmd.FindRecord "[#]", acStart

Search Help for Wildcard Characters to see why.- Hide quoted text -

- Show quoted text -

Reply With Quote
  #7  
Old   
imb
 
Posts: n/a

Default Re: FindRecord - 12-05-2010 , 01:34 PM



Hi Marsh,

Your hint to convert "#" to "[#]" as argument for FindRecord or
FindFirst is _the_ solution for my problem. Thank you.

The reason for using FindRecord or FindFirst I do not remember
anymore, it is too long ago, in the times before Access98.
With unsorted records (FindRecord) I needed a match, with sorted
records I needed a match OR the next higher occurance.
But I will study the functionality of the procedure again, and also
how FindRecord and FindFirst work exactly.

About the help, with Access98 I had the English and the Dutch version
installed, and I could find anything.
With Access2003 I have only the Dutch version, so "wildcard" is not
found. Using the Dutch word "jokerteken" (I almost never use this
word) gave better results.

Imb.



On Dec 5, 1:32*am, Marshall Barton <marshbar... (AT) wowway (DOT) com> wrote:
Quote:
imb wrote:
Whereas I use DoCmd.FindRecord for unsorted fields, I use
already .RecordsetClone.FindFirst for sorted fields.

I don't see how sorting the records should determine which
technique is used.

But also here, FindFirst uses # as a wildcard character.

FindFirst only uses wildcards when you use the Like
operator. *I used Left and = to avoid using a wildcard as
you requested.

Converting with so many quotes makes the logic untransparant, so
probably I will not use that.

There are ways to write that using a constant instead of so
many quotes:

Const QT As string = """"
* .FindFirst "Left([the field], " _
* * & Len(Me.[the text box].Text) & ") = " & QT _
* * & Replace(Me.[the text box].Text, QT, QT & QT) & QT

I think more in using FindRecord or FindFirst in those cases that the
search-for value contains no wildcard characters, whereas with
wildcard characters I will loop through the RecordsetClone set.

That doesn't make sense to me. *You do not need to check for
wildcards in the search string. *You can just add the [ ] to
hide them using the Replace function. *For example:
* .FindFirst "[the field] Like '*" & Replace(Me.[the text
box].Text, "#", "[#]") & "*' "

If you do not want users to be able to use any wildcards,
but want all their characters to be taken literally, you can
neutralize all wildcards with code along these lines:

Const Wildcards As String = "[*#?" * * ' [ must be first
Dim Search As String, k As Integer
* *Search = Me.[the text box].Text
* *For k = 1 To Len(Wildcards)
* * * Search = Replace(Search, Mid(Wildcards,k,1), "[" &
Mid(Wildcards,k,1) & "]")
* *Next k
* *.FindFirst "[the field] Like ""*" & Search & "*"" "
* * * . . .

Looping through a recordset is an order of magnitude slower
then FindFirst.

A complexing factor is that I want to use the "*" as wildcard
character, but not all the rest.

The above allows you to use * to search anywhere in the
field.

By the way, using A2003, I could not find any help on Wildcard
characters, nor did FindRecord nor Findfirst mention this.

Maybe you looked in online help?? *I found it in both Access
Offline Help and in VBA Help.
--
Marsh



On Dec 4, 11:33 pm, Marshall Barton wrote:
FindRecord is not that versatile. Try something more like:

With Me.RecordsetClone
.FindFirst "Left([the field], " _
& Len(Me.[the text box].Text) & ") = """ _
& Replace(Me.[the text box].Text, """", """""") _
& """"
If Not .NoMatch Then Me.Boolmark = .Bookmark
End With
--
Marsh

imb wrote:
Yes, it works, but this is not the way I'm looking for.
I was hoping that there was some argument that can be set to eliminate
the wildcharacter behaviour, and search for text as it is typed in.

In my application the user types in a search text in some kind of
command line, and at the same time the form displays the matching
record (or indicates that no record was found).
It is a little unhandy if a user must surround the # bij square
brackets, for just the #-character.

On Dec 4, 9:19 pm, Marshall Barton wrote:
imb wrote:
When I use

DoCmd.FindRecord "#", acStart

in a form, the form shows a record that starts with a number.
But I want to go to a record that starts with "#". How can I do that?

Try using:
DoCmd.FindRecord "[#]", acStart

Search Help for Wildcard Characters to see why.- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Reply With Quote
  #8  
Old   
Marshall Barton
 
Posts: n/a

Default Re: FindRecord - 12-05-2010 , 04:39 PM



imb wrote:
Quote:
Your hint to convert "#" to "[#]" as argument for FindRecord or
FindFirst is _the_ solution for my problem. Thank you.
Glad to hear it. Sorry it took so long to get a grip on
your question.

Quote:
The reason for using FindRecord or FindFirst I do not remember
anymore, it is too long ago, in the times before Access98.
With unsorted records (FindRecord) I needed a match, with sorted
records I needed a match OR the next higher occurance.
But I will study the functionality of the procedure again, and also
how FindRecord and FindFirst work exactly.
Ahhh. Sorting makes more sense if you're talking about
using FindRecord's other options. But then there's
FindNext, FindPrevious and FindLast as alternatives.

The reason I avoid DoCmd.FindRecord in favor of
RecordsetClone.Find... is because FindRecord has an clumsy
way of specifying the field to search and it does not allow
you to specify the condition as a full where clause, allow
you to specify the form to search or to check if the match
failed.

Quote:
About the help, with Access98 I had the English and the Dutch version
installed, and I could find anything.
With Access2003 I have only the Dutch version, so "wildcard" is not
found. Using the Dutch word "jokerteken" (I almost never use this
word) gave better results.
You're way ahead of me there. I would have no hope of
finding anything in the Dutch version ;-)

Quote:
On Dec 5, 1:32*am, Marshall Barton <marshbar... (AT) wowway (DOT) com> wrote:
imb wrote:
Whereas I use DoCmd.FindRecord for unsorted fields, I use
already .RecordsetClone.FindFirst for sorted fields.

I don't see how sorting the records should determine which
technique is used.

But also here, FindFirst uses # as a wildcard character.

FindFirst only uses wildcards when you use the Like
operator. *I used Left and = to avoid using a wildcard as
you requested.

Converting with so many quotes makes the logic untransparant, so
probably I will not use that.

There are ways to write that using a constant instead of so
many quotes:

Const QT As string = """"
* .FindFirst "Left([the field], " _
* * & Len(Me.[the text box].Text) & ") = " & QT _
* * & Replace(Me.[the text box].Text, QT, QT & QT) & QT

I think more in using FindRecord or FindFirst in those cases that the
search-for value contains no wildcard characters, whereas with
wildcard characters I will loop through the RecordsetClone set.

That doesn't make sense to me. *You do not need to check for
wildcards in the search string. *You can just add the [ ] to
hide them using the Replace function. *For example:
* .FindFirst "[the field] Like '*" & Replace(Me.[the text
box].Text, "#", "[#]") & "*' "

If you do not want users to be able to use any wildcards,
but want all their characters to be taken literally, you can
neutralize all wildcards with code along these lines:

Const Wildcards As String = "[*#?" * * ' [ must be first
Dim Search As String, k As Integer
* *Search = Me.[the text box].Text
* *For k = 1 To Len(Wildcards)
* * * Search = Replace(Search, Mid(Wildcards,k,1), "[" &
Mid(Wildcards,k,1) & "]")
* *Next k
* *.FindFirst "[the field] Like ""*" & Search & "*"" "
* * * . . .

Looping through a recordset is an order of magnitude slower
then FindFirst.

A complexing factor is that I want to use the "*" as wildcard
character, but not all the rest.

The above allows you to use * to search anywhere in the
field.

By the way, using A2003, I could not find any help on Wildcard
characters, nor did FindRecord nor Findfirst mention this.

Maybe you looked in online help?? *I found it in both Access
Offline Help and in VBA Help.
--
Marsh



On Dec 4, 11:33 pm, Marshall Barton wrote:
FindRecord is not that versatile. Try something more like:

With Me.RecordsetClone
.FindFirst "Left([the field], " _
& Len(Me.[the text box].Text) & ") = """ _
& Replace(Me.[the text box].Text, """", """""") _
& """"
If Not .NoMatch Then Me.Boolmark = .Bookmark
End With
--
Marsh

imb wrote:
Yes, it works, but this is not the way I'm looking for.
I was hoping that there was some argument that can be set to eliminate
the wildcharacter behaviour, and search for text as it is typed in.

In my application the user types in a search text in some kind of
command line, and at the same time the form displays the matching
record (or indicates that no record was found).
It is a little unhandy if a user must surround the # bij square
brackets, for just the #-character.

On Dec 4, 9:19 pm, Marshall Barton wrote:
imb wrote:
When I use

DoCmd.FindRecord "#", acStart

in a form, the form shows a record that starts with a number.
But I want to go to a record that starts with "#". How can I do that?

Try using:
DoCmd.FindRecord "[#]", acStart

Search Help for Wildcard Characters to see why.- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
--
Marsh

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.