UnionWarDog
New member
- Local time
- Today, 17:34
- Joined
- Mar 12, 2025
- Messages
- 6
Hi guys!
I'm trying to export attachments from my table and relabel the file as the name from a column from the table [UnitCard]. Currently it exports them as the name of the attachment.
Here are the column names:
LeadersDBList
It currently extracts the file from GenImage as "GenHQ.bmp" but I want it to use the name from UnitCard and export the file as "Gen Albert S. Johnston.bmp"
Currently there are 251 lines in my table. Here is the module script I'm using to export the files.
Immediate:
ExtractAllAttachments "LeadersDBList","GenImage","E:\TempImages"
I'm trying to export attachments from my table and relabel the file as the name from a column from the table [UnitCard]. Currently it exports them as the name of the attachment.
Here are the column names:
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) |
It currently extracts the file from GenImage as "GenHQ.bmp" but I want it to use the name from UnitCard and export the file as "Gen Albert S. Johnston.bmp"
Currently there are 251 lines in my table. Here is the module script I'm using to export the files.
Code:
Public Sub ExtractAllAttachments(ByVal TableName As String, ByVal AttachmentColumnName As String, ByVal ToDirectory)
Dim rsMainRecords As DAO.Recordset2
Dim rsAttachments As DAO.Recordset2
Set rsMainRecords = CurrentDb.OpenRecordset("SELECT " & AttachmentColumnName & _
" FROM " & TableName & _
" WHERE " & AttachmentColumnName & ".FileName IS NOT NULL")
Do Until rsMainRecords.EOF
Set rsAttachments = rsMainRecords.Fields(AttachmentColumnName).Value
Do Until rsAttachments.EOF
Dim outputFileName As String
outputFileName = rsAttachments.Fields("FileName").Value
outputFileName = ToDirectory & "\" & outputFileName
rsAttachments.Fields("FileData").SaveToFile outputFileName
rsAttachments.MoveNext
Loop
rsAttachments.Close
rsMainRecords.MoveNext
Loop
rsMainRecords.Close
Set rsAttachments = Nothing
Set rsMainRecords = Nothing
End Sub
ExtractAllAttachments "LeadersDBList","GenImage","E:\TempImages"
Last edited: