Like "*a*" in vba??

branston

Registered User.
Local time
Today, 19:17
Joined
Apr 29, 2009
Messages
372
Hi!

Im looking for a function that does the same as the like function in queries (eg like "*a*" would show everything containing the letter a) but for vba code.

Any ideas?
 
you can use 'Like' in code. can't think of another, similar function off hand.
 
branston,

Code:
If InStr(1, Me.SomeFormControl, "a") > 0 Then
   ' Do Something
End If

Wayne
 
Hi!

Im looking for a function that does the same as the like function in queries (eg like "*a*" would show everything containing the letter a) but for vba code.

Any ideas?

What are you trying to do in VBA? If in code you might want the Instr function -

If Instr(1, Me.YourTextBox, "a") > 0 Then...

etc.
 
thanks for all your help so far... The way im trying to use it is to set a link criteria for an openForm command. I basically need to set the form to open where RecNo = Me.RecNo, RevNo = Me.RevNo and Description is like "1 -*"
So far ive tried:

stLinkCriteria = "[RecNo]= '" & Me![RecNo] & "' And [RevNo]= " & Me![RevNo] & "And [Description] like '1 -*'"

am I missing something, or should that work?
 
Dim strWhere As String
Dim lngLen As Long

strWhere = strWhere & "([Name] Like ""*" & Me.txname & "*"") AND "

'See if the string has more than 5 characters (a trailng " AND ") to remove.

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.

strWhere = Left$(strWhere, lngLen)

Courtesy: allenbrowne page.

txtname contains ur serach criteria in ur case "a"...
 
Code:
stLinkCriteria = "[RecNo]= '" & Me![RecNo] & "' And [RevNo]= " & Me![RevNo] & "[B]And [/B][Description] like '1 -*'"

Is RecNo a number or a string? If number drop the quotes.
Same for RevNo
also you need a space before the last And (highlighted)

David
 
Thanks for all your help. Very useful information.
 

Users who are viewing this thread

Back
Top Bottom