VBA Search Code

toleafs

Active Member
Joined
Jun 27, 2005
Messages
498
Hi, any help is greatly appreciated..... I have a dropdown field in a form and a search command button to search within a form. See code below

Private Sub CmdLetterSearch_Click()
Dim LSQLs As String
Dim LSearchStrings As String
Dim RecordCounts As String
Dim lRecCounts As Integer

If Len(cboLetter) = 0 Or IsNull(cboLetter) = True Then
MsgBox "You must enter a search string."


Else

LSearchStrings = cboLetter

'Filter results based on search string
LSQLs = "select * from qRECS"
LSQLs = LSQLs & " where strLetterIndentification = '*" & LSearchStrings & "*'"


Form_frmRECS.RecordSource = LSQLs

lblLetter.Caption = "Letter Identification Details: Filtered by: '" & LSearchStrings & "."

'Clear search string
cboLetter = ""

MsgBox "Results have been filtered. For Letter Identfication Number: " & LSearchStrings & " "

The issue is that the records that can be chosen from the dropdown field may contain symbols ( &, !, *) alonf with text and numbers. The code I have does not filter those out.

Thanks in advance for your help.
 
Between Chr(65) And Chr(90)
This is trying to evaluate if a string is between capital A and capital Z. Between can only be used for numbers and dates (& maybe strings that can evaluate to numbers, such as if 100 is stored as text). To use the between operator for this, the numerical range for the letters would have to be evaluated, not the strings A and Z. So
Between Asc("A") And Asc("Z") or a properly concatenated expression. However, you cannot use wildcards in numeric searches.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Between works on text. Maybe its used incorrectly in such contexts too much, but it can work.
 
Upvote 0
Yes, you were lied to. :cool:
But you have to be careful with text, more so than with numbers.
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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