UnionWarDog
New member
- Local time
- Today, 04:40
- Joined
- Mar 12, 2025
- Messages
- 9
Hi guys,
I have a code to extract the Attachment field of a table but would rather extract the OLE Object field. How can I change the script to pull the OLE Object ([Image]) instead of the Attachment field ([GenImage]). Here is table data:
LeadersDBList
Here is the code:
I have a code to extract the Attachment field of a table but would rather extract the OLE Object field. How can I change the script to pull the OLE Object ([Image]) instead of the Attachment field ([GenImage]). Here is table data:
LeadersDBList
ID | STATE | Size | Utype | GenSide | NationFolder | Unit Name | UnitCard | Image | GenImage |
---|---|---|---|---|---|---|---|---|---|
1 | Bulgarian | Department | Leader | Rebel Genearl | Bulgarian | Department Nr. 2 | Gen Albert S. Johnston | BitmapImage | @(1) |
Here is the code:
Code:
Public Sub ExtractAllAttachments(ByVal TableName As String, ByVal AttachmentColumnName As String, ByVal ToDirectory)
Const cNEW_FILE_FIELD As String = "[UnitCard]"
Dim rsMainRecords As DAO.Recordset2
Dim rsAttachments As DAO.Recordset2
Dim outputFileName As String
Dim NewFile As String
Set rsMainRecords = CurrentDb.OpenRecordset("SELECT " & AttachmentColumnName & ", " & cNEW_FILE_FIELD & _
" FROM " & TableName & _
" WHERE " & AttachmentColumnName & ".FileName IS NOT NULL")
Do Until rsMainRecords.EOF
Set rsAttachments = rsMainRecords.Fields(AttachmentColumnName).Value
Do Until rsAttachments.EOF
outputFileName = rsAttachments.Fields("FileName").Value
NewFile = Trim$(rsMainRecords.Fields(1) & "")
If Len(NewFile) <> 0 Then
NewFile = NewFile & ExtensionOfFile(outputFileName)
Else
NewFile = outputFileName
End If
outputFileName = ToDirectory & "\" & NewFile
'delerte old image
If Len(Dir$(outputFileName))<>0 then
Kill outputFileName
End If
rsAttachments.Fields("FileData").SaveToFile outputFileName
rsAttachments.MoveNext
Loop
rsAttachments.Close
rsMainRecords.MoveNext
Loop
rsMainRecords.Close
Set rsAttachments = Nothing
Set rsMainRecords = Nothing
End Sub