Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Location
    Inverurie
    Posts
    628

    Unanswered: Need some help with my VBA code...

    hi all, I am trying to code a database that ignores the usual link conventions, and runs off code instead.

    When i try to verify that there are no bad characters in the application path, it causes the error to come up.

    here's the part im on about:

    Code:
        'Verify no bad chars in app path.
        strTemp = StripBadChars(strAppPath, "-';/!@#$%^&*()" & Chr$(34), "|")
        If InStr(strTemp, "|") > 0 Then
            MsgBox "App is located at an invalid path.  Please remove invalid characters from path name.", 48, "Fatal Error"
            Quit
        End If
    Now, if i change the >0 part to <0 it goes fine, but then again it hasn't checked the app path. Could anyone help me get past this little bug?

    Incidentally, here's the app path it doesn't seem to be able to verify:

    C:\Documents and Settings\duncana\Desktop\NCR-DCR Database

  2. #2
    Join Date
    Jun 2004
    Posts
    92
    Without the StripBadChars function, which I'm not going to spend the time to recreate, I can't tell you the problem.

  3. #3
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    It is hard to say without seeing what is returned by the StripBadChars function. But there are a couple things I noticed. First / is acceptable in a path. / and \ are interchangeable. Also I noticed you are stripping (assuming that is what you are doing) out hypens (-), but you have a hypen in your path. Could that be the problem?

  4. #4
    Join Date
    Jul 2004
    Location
    Inverurie
    Posts
    628
    I caught on to that one and removed it. Here's the module code to help you:

    Code:
    Public Function StripBadChars(strToParse As String, strListBads As String, strToReplace As String) As String
    '----------------------------------------------------------------------------------------------------
    'DESCRIPTION:
    '------------
    ' This subroutine strips out all specified bad characters from a source string.  It is handy to use
    ' for database operations to prevent errors when executing SQL using single and double quotes, semi-
    ' colons, etc.
    '----------------------------------------------------------------------------------------------------
    'INPUT:
    '------
    ' strToParse    - The string to be cleaned up.
    ' strListBads   - A string list of bad characters to be removed.
    ' strToReplace  - A character (or string) to be used to replace each instance of a 'bad' character in
    '                 the strToParse.  (I typically just replace bads with a tilde '~'.)
    '----------------------------------------------------------------------------------------------------
    ' OUTPUT:
    '--------
    ' The edited string is returned, where all bad characters are replaced as specified.
    '----------------------------------------------------------------------------------------------------
    ' SAMPLE CALL:
    '-------------
    ' RC$ = StripBadChars(strToParse, "'" & chr$(34) & ";", "~")
    '----------------------------------------------------------------------------------------------------
    
    
    'DECLARATIONS
    '------------
        Dim i%
        Dim strRebuilt As String
        Dim strChar As String
        
        'Setup Error Handler
        '-------------------
        Dim strErrNotes As String
        Const Module$ = "Strings.bas", Fx$ = "StripBadChars"
        On Error GoTo StripBadChars_ErrHandler
    
    'INITIALIZE
    '----------
        strRebuilt = ""
        
        
    'MAIN BODY
    '---------
        For i% = 1 To Len(strToParse)
            strChar = Mid$(strToParse, i%, 1)
            If InStr(strListBads, strChar) = 0 Then
                strRebuilt = strRebuilt & strChar
            Else
                strRebuilt = strRebuilt & strToReplace
            End If
        Next i%
        
        
    'WRAP-UP
    '-------
        StripBadChars = strRebuilt
        
    WrapUp:
    
    Exit Function
    
    
    'CODE SNIPPETS
    '-------------
    
    
    'ERROR HANDLER
    '-------------
    StripBadChars_ErrHandler:
        strErrNotes = ""
        Call LogError(conSevMajor, Err, DBEngine.Errors, Module$, Fx$, strErrNotes)
        
        StripBadChars = "Error"
    
    Resume WrapUp
    
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •