Results 1 to 6 of 6

Thread: [RESOLVED] On Exit textbox function. check entry??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    Resolved [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:
    1. Private Sub ProjectName_Exit(Cancel As Integer)
    2. If InStr(1, ProjectName.Value, "/") > 0 Then MsgBox ("/ character not allowed"): ProjectName.SetFocus
    3. If InStr(1, ProjectName.Value, "\") > 0 Then MsgBox ("\ character not allowed"): ProjectName.SetFocus
    4. If InStr(1, ProjectName.Value, ":") > 0 Then MsgBox (": character not allowed"): ProjectName.SetFocus
    5. If InStr(1, ProjectName.Value, "*") > 0 Then MsgBox ("* character not allowed"): ProjectName.SetFocus
    6. If InStr(1, ProjectName.Value, "?") > 0 Then MsgBox ("? character not allowed"): ProjectName.SetFocus
    7. If InStr(1, ProjectName.Value, "<") > 0 Then MsgBox ("< character not allowed"): ProjectName.SetFocus
    8. If InStr(1, ProjectName.Value, ">") > 0 Then MsgBox ("> character not allowed"): ProjectName.SetFocus
    9. If InStr(1, ProjectName.Value, "|") > 0 Then MsgBox ("| character not allowed"): ProjectName.SetFocus
    10. If InStr(1, ProjectName.Value, ",") > 0 Then MsgBox (", character not allowed"): ProjectName.SetFocus
    11.  
    12. End Sub
    Last edited by strobinson1; Sep 23rd, 2005 at 05:59 AM.

  2. #2
    Hyperactive Member
    Join Date
    May 2005
    Posts
    307

    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    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....???

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: On Exit textbox function. check entry??

    As this pertains to Access VBA rather than VB, it has been moved to Office Development.

  5. #5
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    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:
    1. Dim strKeyPressed
    2.   strKeyPressed = Chr(KeyAscii)
    3.   Select Case strKeyPressed
    4.     Case "/", "\", ":", "*", "?", "<", ">", "|", ","
    5.       DoCmd.CancelEvent
    6.   End Select
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    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
  •  



Click Here to Expand Forum to Full Width