Solved Hiding Tables Delete Attachment (1 Viewer)

Pac-Man

Active member
Local time
Today, 05:47
Joined
Apr 14, 2020
Messages
408
Hello,

I'm using the following code to hide my tables:

Rich (BB code):
Function HideTables(Hide As Boolean)
    Dim db As Database
    Dim tdf As TableDef
    Dim Tbl As String
    Set db = CurrentDb
    For Each tdf In db.TableDefs
        Tbl = tdf.name
        If Not (Tbl Like "USys*" Or Tbl Like "MSys*" Or Tbl Like "~*") Then
            If Hide = True Then
                tdf.Attributes = dbHiddenObject
            Else
                tdf.Attributes = 0
            End If
        End If
    Next
        Set db = Nothing
End Function

Problem is, one of my tables has attachment. When this function is called at startup, attachment from the record is deleted. I don't know what's going on. I need help how to fix this.

Best Regards
Abdullah
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:47
Joined
May 7, 2009
Messages
19,169
yes, for sometimes a read about hiding the table causes errors.
the safest:
Code:
Function HideTables(Hide As Boolean)
    Dim db As Database
    Dim tdf As TableDef
    Dim Tbl As String
    Set db = CurrentDb
    For Each tdf In db.TableDefs
        Tbl = tdf.Name
        If Not (Tbl Like "USys*" Or Tbl Like "MSys*" Or Tbl Like "~*") Then
            If Hide = True Then
                Application.SetHiddenAttribute acTable, Tbl, True
                'tdf.Attributes = tdf.Attributes Or dbHiddenObject
            Else
                Application.SetHiddenAttribute acTable, Tbl, False
                'tdf.Attributes = 0
            End If
        End If
    Next
        Application.RefreshDatabaseWindow
        Set db = Nothing
End Function
on navigation option.. untick show hidden objects.
 

Pac-Man

Active member
Local time
Today, 05:47
Joined
Apr 14, 2020
Messages
408
yes, for sometimes a read about hiding the table causes errors.
the safest:
Code:
Function HideTables(Hide As Boolean)
    Dim db As Database
    Dim tdf As TableDef
    Dim Tbl As String
    Set db = CurrentDb
    For Each tdf In db.TableDefs
        Tbl = tdf.Name
        If Not (Tbl Like "USys*" Or Tbl Like "MSys*" Or Tbl Like "~*") Then
            If Hide = True Then
                Application.SetHiddenAttribute acTable, Tbl, True
                'tdf.Attributes = tdf.Attributes Or dbHiddenObject
            Else
                Application.SetHiddenAttribute acTable, Tbl, False
                'tdf.Attributes = 0
            End If
        End If
    Next
        Application.RefreshDatabaseWindow
        Set db = Nothing
End Function
on navigation option.. untick show hidden objects.
Thanks a lot. It helped.
 

isladogs

MVP / VIP
Local time
Today, 00:47
Joined
Jan 14, 2017
Messages
18,186
Several months on and I've just had this thread pointed out to me
As I never use attachment fields, I hadn't experienced this issue before despite regularly working with deep hidden tables.

However, having tested it I can confirm that deep hiding a table does cause attachment field data to be lost (apparently).
Standard hiding of a table either by code (post #2) or from the nav pane has no adverse effects.

Whilst I could just glibly say that is yet another reason to avoid attachments fields....notice I wrote apparently above!

I wondered whether a similar issue would occur with another complex datatype - column history in memo/long text fields (CHM field).
So I added a long text field to the table with the 'lost attachments' and set the Append Only property to Yes.
On changing back to normal view, the 'lost' attachment data reappeared!!!!!

Deep hiding the table again didn't cause the data to be lost again.
It doesn't matter whether the CHM field contained any data ...it just needs to exist!
I suspect that having an MVF field might work in the same way (untested)

NOTE: standard field types such as short text, number etc didn't work. It needs the extra field to be a complex datatype
I will investigate further in a day or two by looking at the contents of the associated deep hidden system table (starting with f_...)

In reality, I think it is just an Access glitch

Even if its too late for the OP, I hope this helps someone in the future
 

Pac-Man

Active member
Local time
Today, 05:47
Joined
Apr 14, 2020
Messages
408
Several months on and I've just had this thread pointed out to me
As I never use attachment fields, I hadn't experienced this issue before despite regularly working with deep hidden tables.

However, having tested it I can confirm that deep hiding a table does cause attachment field data to be lost (apparently).
Standard hiding of a table either by code (post #2) or from the nav pane has no adverse effects.

Whilst I could just glibly say that is yet another reason to avoid attachments fields....notice I wrote apparently above!

I wondered whether a similar issue would occur with another complex datatype - column history in memo/long text fields (CHM field).
So I added a long text field to the table with the 'lost attachments' and set the Append Only property to Yes.
On changing back to normal view, the 'lost' attachment data reappeared!!!!!

Deep hiding the table again didn't cause the data to be lost again.
It doesn't matter whether the CHM field contained any data ...it just needs to exist!
I suspect that having an MVF field might work in the same way (untested)

NOTE: standard field types such as short text, number etc didn't work. It needs the extra field to be a complex datatype
I will investigate further in a day or two by looking at the contents of the associated deep hidden system table (starting with f_...)

In reality, I think it is just an Access glitch

Even if its too late for the OP, I hope this helps someone in the future
Thanks a lot for finding the way out and detailed reply. Initially I adopted the code from post # 2 to hide only that table which contain attachment while other tables were deep hidden. Later I had to remove attachment field from my database due to some other reasons and now my database don't have attachments. So all my takes are deep hidden. If i need to add some attachments in the future, your reply will be of great help.

Thanks again and regards
 

isladogs

MVP / VIP
Local time
Today, 00:47
Joined
Jan 14, 2017
Messages
18,186
Glad to see you scrapped the attachment field(s). That was a wise decision.

However, I'm intrigued by this rather odd issue and the solution that I found by chance so intend to do a bit more digging.
Having said that I very much doubt there are many developers who want to deep hide tables containing complex datatypes such as attachment fields
 

Users who are viewing this thread

Top Bottom