joyfullservice / msaccess-vcs-addin

Synchronize your Access Forms, Macros, Modules, Queries, Reports, and more with a version control system.
Other
201 stars 39 forks source link

clsDbHiddenAttribute (possibly others) fails when objectname (to be exported) has & in name #520

Open datenbank-projekt opened 1 month ago

datenbank-projekt commented 1 month ago

I am taking over an old Access database. Tablesnames have ' and & characters in them. Exporping fails in line If Application.GetHiddenAttribute(contType, doc.Name) Then in clsDbHiddenAttribute when doc.Name has a &.

Maybe something like this helps (not my code, but our favorites AI's):

Function EscapeObjectName(objectName As String) As String
    Dim safeName As String
    Dim i As Integer
    Dim c As String
    Dim specialCharacters As String

    ' Define special characters that need escaping
    specialCharacters = "~`!@#$%^&*()-+=|\/{}[]:;'<>,.?/ "

    ' Check if the name contains any special characters
    For i = 1 To Len(objectName)
        c = Mid(objectName, i, 1)
        If InStr(specialCharacters, c) > 0 Then
            ' If it contains special characters, escape the whole name
            EscapeObjectName = "[" & objectName & "]"
            Exit Function
        End If
    Next i

    ' If no special characters are found, return the original name
    EscapeObjectName = objectName
End Function

'example usage:

Sub TestEscapeObjectName()
    Dim unsafeName As String
    Dim safeName As String

    unsafeName = "Table&Name"
    safeName = EscapeObjectName(unsafeName)

    Debug.Print "Original Name: " & unsafeName
    Debug.Print "Safe Name: " & safeName

    ' Example usage in a query
    Dim sql As String
    sql = "SELECT * FROM " & safeName
    Debug.Print "SQL: " & sql

    ' Example usage in checking hidden attribute
    Dim isHidden As Boolean
    isHidden = Application.GetHiddenAttribute(acTable, safeName)
    Debug.Print "Is Hidden: " & isHidden
End Sub
joyfullservice commented 1 month ago

I am having difficulty reproducing this issue... I created a table named tblSpecial '&' Name, set the hidden attribute, and it exported just fine for me. I have a couple follow-up questions:

Thanks!

datenbank-projekt commented 1 month ago

Windows 64 bit + Office 2016 pro 64bit

a) Version 4.0.34 b) no special settings that I know of (windows and office: German) c) I am not sure if I can do this. I will see and maybe reply again.