[RESOLVED] On Exit textbox function. check entry??
I'm using MSAccess 2003.
After someone has typed some text into a textbox, I want to use that text to create a directory in that name on my computer.
Obviously there are some characters that you cannot use like \ / * etc etc.
how can I check that these aren't used and if they are, stop them from exiting the text box until they rectify it?
I was trying this, but after it runs, it still exits the text box. and i'd have to write a line for EVERY character not allowed?!
VB Code:
Private Sub ProjectName_Exit(Cancel As Integer)
If InStr(1, ProjectName.Value, "/") > 0 Then MsgBox ("/ character not allowed"): ProjectName.SetFocus
If InStr(1, ProjectName.Value, "\") > 0 Then MsgBox ("\ character not allowed"): ProjectName.SetFocus
If InStr(1, ProjectName.Value, ":") > 0 Then MsgBox (": character not allowed"): ProjectName.SetFocus
If InStr(1, ProjectName.Value, "*") > 0 Then MsgBox ("* character not allowed"): ProjectName.SetFocus
If InStr(1, ProjectName.Value, "?") > 0 Then MsgBox ("? character not allowed"): ProjectName.SetFocus
If InStr(1, ProjectName.Value, "<") > 0 Then MsgBox ("< character not allowed"): ProjectName.SetFocus
If InStr(1, ProjectName.Value, ">") > 0 Then MsgBox ("> character not allowed"): ProjectName.SetFocus
If InStr(1, ProjectName.Value, "|") > 0 Then MsgBox ("| character not allowed"): ProjectName.SetFocus
If InStr(1, ProjectName.Value, ",") > 0 Then MsgBox (", character not allowed"): ProjectName.SetFocus
End Sub
Re: On Exit textbox function. check entry??
ive got this function that removes any special characters when focus is lost from text1. hope it helps somewhat.
Dim strCur as string
Dim iCount as long
dim a as string
strCur = "!@#$%^&*()?><~`+=|\/.',{}[];:-%_ "
For iCount = 0 To Len(strCur)
a = Replace(Text1.text, Mid(strCur, iCount + 1, 1), "")
Next
Text1.text = a
Re: On Exit textbox function. check entry??
Yeah ok, that's much simpler coding :)
I guess I'll just have to give them a msgbox box to notify them if it changes...
unless you know how to give focus back to the textbox....???
Re: On Exit textbox function. check entry??
As this pertains to Access VBA rather than VB, it has been moved to Office Development.
Re: On Exit textbox function. check entry??
This is even easier...
Preventing the key from being pressed in the box in the first place... Place this code in the KeyPress event of the textbox you want to control..
VB Code:
Dim strKeyPressed
strKeyPressed = Chr(KeyAscii)
Select Case strKeyPressed
Case "/", "\", ":", "*", "?", "<", ">", "|", ","
DoCmd.CancelEvent
End Select
Re: On Exit textbox function. check entry??
ah. cunning. I like it :)
that's what I needed...
the docmd.CancelEvent line.
CHEERS PEEPS!