Rename and detach attachments in multiple rt fields

Experts,

I have a form with multiple rich text fields each form does contain at least 1 embedded attachment.
For each rich text field (multiple rt fields exist i.e. more then 15 on the form).
I want to change the attached file name to DocNum & "_" & AttachName then put in a directory.
Prevously I have used the following code to extract a rich text item from a specific field but this form has multiple richtext fields.
Any help modify this code is needed fast!

If doc.HasEmbedded Then
 Set rtitem = doc.GetFirstItem( "FormBodyNat" ) ' name of field to look for attachment
   Forall o In rtitem.EmbeddedObjects
    If o.Type = EMBED_ATTACHMENT Then  
     Call o.ExtractFile( "h:\data\RMs\"+ FName+".doc") ' check file path for new location
     Call doc.Save( False, False)   ' no save and no change in doc status
    End If
End Forall

LVL 1
mcjannAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HemanthaKumarCommented:
Try this

      If doc.HasEmbedded Then
            Forall fld In doc.Items
                  If fld.Type = RICHTEXT Then                        
                        Forall o In fld.EmbeddedObjects
                              If o.Type = EMBED_ATTACHMENT Then  
                                    Call o.ExtractFile( "h:\data\RMs\"+ FName+".doc") ' check file path for new location
                                    Call doc.Save( False, False)   ' no save and no change in doc status
                              End If
                        End Forall
                  End If
            End Forall
      End If

~Hemanth
0
mcjannAuthor Commented:
I incorporated the script like this and I am getting a type mismatch

Sub Click(Source As Button)
Dim session As New NotesSession  
Dim db As NotesDatabase  
Dim collection As NotesDocumentCollection  
Dim doc As NotesDocument  
Dim rtitem As Variant
      
Set db = session.CurrentDatabase  
Set collection = db.UnprocessedDocuments  
  For i = 1 To collection.Count    
            
     Set doc = collection.GetNthDocument( i )
      CRNum=doc.DocNum(0)
If doc.HasEmbedded Then
  Forall fld In doc.Items
    If fld.Type = RICHTEXT Then                    
      Forall o In fld.EmbeddedObjects
        If o.Type = EMBED_ATTACHMENT Then  
        Call o.ExtractFile( "h:\data\Night & Day\"+ CRNum+ "_" + o.source) ' check file path for new location
        Call doc.Save( False, False)   ' no save and no change in doc status
End If
End Forall
End If
End Forall
End If
Next
End Sub
0
HemanthaKumarCommented:
Can you debug and let me know which line ?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Sjef BosmanGroupware ConsultantCommented:
CRNum is a number?

Change
>      Call o.ExtractFile( "h:\data\Night & Day\"+ CRNum+ "_" + o.source) ' check file path for new location
to
       Call o.ExtractFile( "h:\data\Night & Day\" & CRNum & "_" + o.source) ' check file path for new location
0
mcjannAuthor Commented:
No, CRNum is a text field on the form.

I modified to the following and still get a type mismatch.

Forall fld In doc.Items
  If fld.Type = RICHTEXT Then      
Forall o In fld.EmbeddedObjects
                                    
     If o.Type = EMBED_ATTACHMENT Then  
          Print o.Type
         ' Call o.ExtractFile( "H:\DATA\Night & Day\" & CRNum & "_" + o.source) ' check file path for new location
          'Call doc.Save( False, False)   ' no save and no change in doc status
     End If
End Forall
End If
End Forall
End If
I am attempting anything to get it to work. Will the Forall fld In doc.Items cycle through all fields on the form?
0
p_parthaCommented:
Sub Click(Source As Button)
on error goto par
Dim session As New NotesSession  
Dim db As NotesDatabase  
Dim collection As NotesDocumentCollection  
Dim doc As NotesDocument  
Dim rtitem As Variant
   
Set db = session.CurrentDatabase  
Set collection = db.UnprocessedDocuments  
 For i = 1 To collection.Count    
         
    Set doc = collection.GetNthDocument( i )
      CRNum=doc.DocNum(0)
If doc.HasEmbedded Then
  Forall fld In doc.Items
   If fld.Type = RICHTEXT Then                    
    Forall o In fld.EmbeddedObjects
      If o.Type = EMBED_ATTACHMENT Then  
      Call o.ExtractFile( "h:\data\Night & Day\"+ CRNum+ "_" + o.source) ' check file path for new location
      Call doc.Save( False, False)   ' no save and no change in doc status
End If
End Forall
End If
End Forall
End If
Next
exit sub
par:
Msgbox "error occurred on line number " & erl & error
exit sub
End Sub

Now tell us the line number
0
mcjannAuthor Commented:
Line 18
0
Sjef BosmanGroupware ConsultantCommented:
Or use the debugger :)
0
p_parthaCommented:
try this :

      If doc.HasEmbedded Then
                  Forall fld In doc.Items
                        If fld.Type = RICHTEXT Then            
                              If Not Isempty(fld.embeddedobjects) Then
                                    Forall o In fld.EmbeddedObjects
                                          If o.Type = EMBED_ATTACHMENT Then  
                                                Call o.ExtractFile( "h:\data\Night & Day\"+ CRNum+ "_" + o.source) ' check file path for new location
                                                Call doc.Save( False, False)   ' no save and no change in doc status
                                          End If
                                    End Forall
                              End If
                        End If


Partha
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.