hexagon logo

VB code for Form EventClick

I created a form that has the CMM Operators enter in their information at the beginning of a program. Since some of this information is used for filenames, I do not want to allow special characters. In the EventClick section of the Continue button, I added this code...

Dim s As String
Set s = EditBox1.Text
If InStr(s,"*") = 0 Then

MsgBox "hello"

End If


...I get an error message each time I try it. I did this for testing so I only included "*" but finalized I would like to check if the edit boxes contain "\ / : * ? " < > |" if it does, then display a message and not let them continue until it is fixed. Anyone have any ideas?
Thanks again for the help.
Parents
  • I'm actually working with an edit box. I figured out my issue and it was an oversight on my end. Pretty stupid mistake actually.
    Dim eBox1, strSearch, strSearchFor
    Set strSearch = This.Text
    Set strSearchFor = "*"
    
    If InStr(1,strSearch,strSearchFor,vbTextCompare) <> 0 Then
    
    MsgBox "hello"
    
    End If


    This code works. I originally had it =0 so anytime it opened or typed anything, it was true. I only want something to happen it the character shows up so if it does not return 0, it becomes true. I also didn't have a 1 in the first section of my InStr. I used this code in EventChange and it worked perfectly.
  • Glad you got it working. I use the text changed event in our pc-dmis startup form. For the same reason. It's the serial number input field, which becomes part of the filename on the network drive.
Reply Children
No Data