1

Trying to do a simple VBA script to look at a field and if that field contains 99 in the middle then show another field. I can get a normal statement to work i.e. field2 = "5D992" but not a contains statement using wild cards (see script below). I think it might be just my syntax is wrong, any ideas anyone??

Sub OnFormat

    IF rpt.field3.Text.contains "*99*" THEN 
        rpt.field2.visible = false
    Else 
        rpt.field2.Visible = true
    End If

End Sub

Thanks for any suggestions.

1 Answer 1

1

You should be using InStr.

If InStr(1, rpt.field3.Text, "99", vbTextCompare) Then 
   rpt.field2.visible = false 
Else 
    rpt.field2.visible = true 
End If  

See MSDN InStr Function documentation for more information

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this Smittey, but are wildcards not used for this function??
You're welcome! If I understand the question correctly, do you mean using a wildcard character (e.g. '*')? If so, this InStr function will look for 99 in the string supplied to the second argument (rpt.field3.Text) so effectively it is using wildcards, so "*99*"!
Great thanks for the explanation, much appreciated. The script works wonderful now, much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.