Results 1 to 7 of 7
  1. #1
    MEMFBI is offline Advanced Beginner
    Windows 10 Access 2003
    Join Date
    Apr 2020
    Posts
    45

    Don't allow some special characters to be entered in a field


    Hello
    I have a database that creates folders on a network drive, the names of the folders are based on the data entered in specific fields on a form.
    If a user enters a \ it can't build the folders due to the character. What is the best way to not allow the entry of these characters?
    Or perhaps to have the character changed to a -

    Thank you

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Could possibly have code validate every key stroke in textbox using its OnChange (or maybe KeyDown or KeyPress) event. Otherwise, do data validation in textbox BeforeUpdate event if you want to UNDO user input and make them reenter or use AfterUpdate to fix input.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Someone may have a butter way, but mine is
    in the textbox afterupdate event, I scan the whole word to remove bad characters, usage:


    Code:
    sub txtBox_Afterupdate()
    txtBox = FixBadChrsInWord(txtBox)
    end sub

    paste this in a module.

    Code:
    Public Function FixBadChrsInWord(ByVal pvWord)
    Dim i As Integer
    Dim vChr, vNewWord
    
    
    On Error Resume Next
    pvWord = UCase(Trim(pvWord))
    
    
    For i = 1 To Len(pvWord)
      vChr = Mid(pvWord, i, 1)
      vChr = FixBadChar(vChr)
      vNewWord = vNewWord & vChr
    Next
    
    
    FixBadChrsInWord = vNewWord
    End Function
    
    
    private Function FixBadChar(ByVal pvChr)
    'bad chars if:
    'after UCASE the 1 character entered
    'then check these bad ranges:
    Dim iChrNum As Integer
    
    
    pvChr = UCase(pvChr)
    iChrNum = Asc(pvChr)
    
    
    Select Case True
           'period OK
        Case iChrNum = 46
          FixBadChar = pvChr
        Case iChrNum > 32 And iChrNum < 48
           FixBadChar = ""
        Case iChrNum > 57 And iChrNum < 65
           FixBadChar = ""
        Case iChrNum > 91 And iChrNum < 127
           FixBadChar = ""
        Case Else
        FixBadChar = pvChr
    End Select
    End Function

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I think you will have to identify
    -what bad chars you want to remove/not accept OR
    -what are the acceptable chars (probably a better list) for folder names

  5. #5
    MEMFBI is offline Advanced Beginner
    Windows 10 Access 2003
    Join Date
    Apr 2020
    Posts
    45
    I would want to not accept the following:
    | \ ? / ! & % @ *

    Thank you

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Hmmm? So $%#:">< are OK???
    What is your environment?
    I think you may want something like [a-Z,0-9,-,.] as acceptable, but you know your requirement.
    You may get some insight from this article.
    Last edited by orange; 02-02-2023 at 02:52 PM. Reason: spelling

  7. #7
    MEMFBI is offline Advanced Beginner
    Windows 10 Access 2003
    Join Date
    Apr 2020
    Posts
    45
    You are correct. Guess I was just thinking of those characters that some users have entered.
    So the proper wording of my question should have been, how do I limit users from only entering letters (upper and lower) numbers - _ , .

    Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 12-30-2021, 03:02 AM
  2. Replies: 4
    Last Post: 09-14-2016, 11:09 AM
  3. Replies: 6
    Last Post: 05-08-2014, 01:32 PM
  4. Removing special characters
    By crowegreg in forum Queries
    Replies: 3
    Last Post: 02-26-2014, 11:56 AM
  5. Special Characters
    By orgelizer in forum Access
    Replies: 0
    Last Post: 03-20-2007, 08:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums