theinviter
Registered User.
- Local time
- Today, 13:59
- Joined
- Aug 14, 2014
- Messages
- 273
Dears;
I need your kind support to modify the below to get the attachment from subforum in maniform.
Main form = Holiday_Dialysis
Subform = Documents
attachment filed = Sigend_Form
as i get error in " If Me.Documents.Form.Recordset.Fields("Sigend_Form").AttachmentCount > 0 Then"
the complete code below.
I need your kind support to modify the below to get the attachment from subforum in maniform.
Main form = Holiday_Dialysis
Subform = Documents
attachment filed = Sigend_Form
as i get error in " If Me.Documents.Form.Recordset.Fields("Sigend_Form").AttachmentCount > 0 Then"
the complete code below.
Code:
Private Sub AttachToCollection()
Dim rsAttach As DAO.Recordset2
Dim sPath As String
Dim sFile As String
Dim i As Integer
sPath = Environ$("Temp") & "\"
Set colAttach = New Collection
If Me.Documents.Form.Recordset.Fields("Sigend_Form").AttachmentCount > 0 Then
Set rsAttach = Me.Documents.Form.Recordset.Fields("Sigend_Form").Value
With rsAttach
If Not (.BOF And .EOF) Then
.MoveFirst ' Move to the first record
Do Until .EOF ' Loop through all attachments
i = i + 1 ' Increment counter for collection key
sFile = sPath & .Fields("FileName") ' Construct full file path
If Len(Dir$(sFile)) > 0 Then
Kill sFile
End If
colAttach.Add sFile, i & ""
.Fields("FileData").SaveToFile sFile
.MoveNext ' Move to the next attachment
Loop
End If
.Close ' Close the attachment recordset
End With
End If
End Sub
Last edited: