All,
I have code that is making file directory if needed, counts number of files if folder, adds a leading number to the name of the attachment in a field, detaches and writes the new name of the detached file to a field.
My problem is: If I have more then one attachment then it will retname the file name completely and drop the file extension. So that if the attachment name was hi.pdf, the file would end up 1 ATTMN
This code is run from a view.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim Num As Variant
Dim dis As Variant
Dim num1 As Variant
Dim rtitem As Variant
Dim view As NotesView
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set doc = collection.GetFirstDocument()
Set view = db.GetView( "Working Parts File" )
Set rtitem = doc.GetFirstItem( "DataSheet" )
Num = doc.Num
dis = doc.DisplayAppDate
num1 = doc.Num_2
If Dir( "C:\Test\" & Num1(0), 16) > "" Then
If Dir( "C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0) , 16) > "" Then
Else
Mkdir "C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0)
End If
Else
Mkdir "C:\Test\" & Num1(0)
If Dir( "C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0) , 16) > "" Then
Else
Mkdir "C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0)
End If
End If
Dim eOArray As Variant
eOArray = rtitem.EmbeddedObjects
If Isempty(eOArray)Then
Else
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
nam = ( o.Name )
fileName$ = Dir("C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0) & "\" & "*")
count = 0
Do While fileName$ <> ""
fileName$ = Dir$()
count = count +1
Loop
Call o.ExtractFile("C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0) & "\" & count & " " & nam)
Call o.Remove
nam = count & " " & nam
Call rtitem.AppendText(nam)
Call rtitem.AddNewLine( 1 )
Call doc.Save( True, True )
Else
End If
End Forall
End If
End If
End Sub
Thanks in advance for any help.
Teri