Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
datenbank-projekt opened this issue Jul 9, 2024 · 2 comments
Labels
need more details Further information needed to understand issue

Comments

@datenbank-projekt
Copy link

datenbank-projekt commented Jul 9, 2024

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 joyfullservice added the need more details Further information needed to understand issue label Jul 9, 2024
@joyfullservice
Copy link
Owner

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:

  • Which version of the add-in are you using? (i.e. 4.0.36)
  • Do you have anything special in the locale/language settings for your computer?
  • Could you upload a small example database demonstrating the issue?

Thanks!

@datenbank-projekt
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more details Further information needed to understand issue
Projects
None yet
Development

No branches or pull requests

2 participants