Solved Using a wildcard in vb code

mistyinca1970

Member
Local time
Today, 15:27
Joined
Mar 17, 2021
Messages
117
I have discovered that the "*" does not seem to work as a wildcard in my code. I want the graphic to show up for records whose Company begins with "EMD". What is the correct way to express wildcards in vb coding? Thank you,

Code:
Private Sub Form_Current()

If (txtCompany = "EMD*") Then
        DoCmd.SetProperty "imgEMD", acPropertyVisible, "-1"
    End If
    If (txtCompany <> "EMD*") Then
        DoCmd.SetProperty "imgEMD", acPropertyVisible, "0"
    End If

End Sub
 
Like does not "just work" (so to speak), comprehensively, in VBA. But you can use Instr()
 
I want the graphic to show up for records whose Company begins with "EMD"
if left(txtCompany,3) = "EMD" then
 
However you can use like with a wild card in vba
if txtCompany like "EMD*"

So not sure what @Isaac means by
like does not "just work" (so to speak), comprehensively
I guess that means not as robust as sql.
 
However you can use like with a wild card in vba
if txtCompany like "EMD*"

So not sure what @Isaac means by

I guess that means not as robust as sql.
That's a generous assumption, but in this case it meant I was flat-out wrong. I don't think I've used that much, before, if ever. Learned something new today!

So now the OP has three methods - including their first choice :)
 

Users who are viewing this thread

Back
Top Bottom