![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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? |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
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. |
#5
| |||
| |||
|
|
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 - |
#6
| |||||||
| |||||||
|
|
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. |
|
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 - |
#7
| |||
| |||
|
|
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 - |
#8
| ||||
| ||||
|
|
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. |
|
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 - |
![]() |
| Thread Tools | |
| Display Modes | |
| |