Results 1 to 5 of 5
  1. #1
    krabine is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Posts
    1

    How do I prevent < > : " / \ | ? * from being in a field?

    I have a form that a user enters part information about among other things and I use 3 of those fields combined together to be used as an automatic filename for a word document that I transfer all the info over to?



    The user enters a pin number and from a table that I have it does a DLOOKUP to get the part number and enters that automatically into the part number field. I have a button that saves the record, opens a word template, transfers certain fields to the form fields in the word template and then saves it. Today I just had an issue where the file didnt save because it had a "/" in the part number. I have removed all of those from the part info table that the DLOOKUP references but I still let the user enter their own info into that field incase there are issues with the info table.


    How do I prevent the user from entering those illegal characters that will eventually be in a filename?

  2. #2
    Mpike926's Avatar
    Mpike926 is offline Advanced Beginner
    Windows 7 32bit Access 2010 64bit
    Join Date
    May 2012
    Location
    Florida
    Posts
    43
    Are part numbers strictly Numeric? If so you could change the properties of the control to general number and it would allow only numbers to be entered.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    If this is an alpha/numeric value, would have to use VBA code to validate/correct the input. This validation can be done with each keystroke or after input is completed. Otherwise, use a combobox with LimitToList set to yes.
    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.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I use a function to check for special characters.
    Code:
    Public Function SpecialCharacters(ByRef strCheckThis As String) As Boolean
    
    'Use the following for your msgbox. This includes spaces for readability.
    'strDontWant = "/ " & ", " & "\ " & ". " & """" & " & " & "# " & "* " & "( " & ") " & ":"
        
    Dim intCount As Integer
    Dim strCompare As String
    Dim strDontWant As String
    Dim strFront As String
    Dim strBack As String
    
    strCompare = ""
    strDontWant = "/" & "," & "\" & "." & """" & "&" & "#" & "*" & "(" & ")" & ":"
    SpecialCharacters = 0
    For intCount = 1 To Len(strCheckThis)
    strCompare = Mid(strCheckThis, intCount, 1)
        If InStr(strDontWant, strCompare) <> 0 Then
        
            strFront = Left(strCheckThis, intCount - 1)
            strBack = Mid(strCheckThis, intCount + 1, Len(strCheckThis) - intCount)
            strCheckThis = strFront & "_" & strBack
            SpecialCharacters = -1
            
        End If
    Next intCount
    
    End Function

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    perhaps you could use an input mask - see this link

    https://support.office.com/en-gb/art...2-4a47832de8da

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

Similar Threads

  1. Replies: 5
    Last Post: 11-23-2014, 03:54 PM
  2. Replies: 4
    Last Post: 06-06-2014, 08:50 AM
  3. Replies: 3
    Last Post: 04-22-2013, 06:08 AM
  4. Replies: 1
    Last Post: 03-03-2012, 10:17 PM
  5. Replies: 16
    Last Post: 07-22-2011, 09:23 AM

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