|
-
Sep 23rd, 2005, 05:29 AM
#1
Thread Starter
Addicted Member
[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
Last edited by strobinson1; Sep 23rd, 2005 at 05:59 AM.
-
Sep 23rd, 2005, 05:33 AM
#2
Hyperactive Member
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
-
Sep 23rd, 2005, 05:41 AM
#3
Thread Starter
Addicted Member
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....???
-
Sep 23rd, 2005, 05:46 AM
#4
Re: On Exit textbox function. check entry??
As this pertains to Access VBA rather than VB, it has been moved to Office Development.
-
Sep 23rd, 2005, 05:55 AM
#5
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
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Sep 23rd, 2005, 05:58 AM
#6
Thread Starter
Addicted Member
Re: On Exit textbox function. check entry??
ah. cunning. I like it 
that's what I needed...
the docmd.CancelEvent line.
CHEERS PEEPS!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|