Solved Using a wildcard in vb code (1 Viewer)

mistyinca1970

Member
Local time
Today, 04:14
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
 

Isaac

Lifelong Learner
Local time
Today, 04:14
Joined
Mar 14, 2017
Messages
8,777
Like does not "just work" (so to speak), comprehensively, in VBA. But you can use Instr()
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:14
Joined
May 21, 2018
Messages
8,529
I want the graphic to show up for records whose Company begins with "EMD"
if left(txtCompany,3) = "EMD" then
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:14
Joined
May 21, 2018
Messages
8,529
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.
 

Isaac

Lifelong Learner
Local time
Today, 04:14
Joined
Mar 14, 2017
Messages
8,777
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

Top Bottom