Link to home
Start Free TrialLog in
Avatar of Armando Vilela Baiões
Armando Vilela BaiõesFlag for Portugal

asked on

select parts of text in a OLE (word document) field in a form an pass it to another OLE field

I have a document in an OLE field wich contains a whole document in word, the objective is to split parts of the text into separate other fields (OLE too). The code that i have works fine, but when it paste the text, there is a part that is missing. the first headding.

This is my code so far:

Private Sub Command17_Click()



Me.WordDocData.SetFocus
 Set rngSearch = Me.WordDocData.Range
 With rngSearch.Find

     Do
         idx = idx + 1
         .ClearFormatting
         .Text = ""
         .Style = "Scene"
         .Forward = True
         .Format = True
         .Execute
        
         rngSearch.Collapse wdCollapseEnd
         rngStart = rngSearch.End
         
         .ClearFormatting
         .Text = ""
         .Style = "Corta"
         .Forward = True
         .Format = True
         .Execute
        
         rngSearch.Collapse wdCollapseStart
         rngEnd = rngSearch.Start
         
         If rngStart <> rngEnd Then
             Set myRange = Me.WordDocData.Range(rngStart, rngEnd)
             myRange.Copy
         Forms!frmImportWord!frmCENASSplit.SetFocus
         frmCENASSplit!Scene.SetFocus
         DoCmd.GoToRecord , "", acNewRec
         DoCmd.RunCommand acCmdPaste
         Else
             Exit Do
         End If
       
      Loop While idx < 1000
   
 End With
 End Sub

Open in new window


anyone can help me to figure out, whats missing?

Thanks, and best regards
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

your code appears to be copying what is in the specified style only. Paste a sample document if you want us to experiment getting what is in the tag above too. thanks.
Hi,

pls try
Me.WordDocData.SetFocus
 Set rngSearch = Me.WordDocData.Range
 With rngSearch.Find
     Do
         idx = idx + 1
         .ClearFormatting
         .Text = ""
          .Style = "Scene"
         .Forward = True
         .Format = True
         .Execute
         rngSearch.Collapse wdCollapseStart
         rngStart = rngSearch.Start
         .ClearFormatting
         .Text = ""
         .Style = "Corta"
         .Forward = True
         .Format = True
         .Execute
         rngSearch.Collapse wdCollapseStart
         rngEnd = rngSearch.Start
         If rngStart <> rngEnd Then
             'Set myRange = ActiveDocument.Range(rngStart, rngEnd)
             Set myRange = Me.WordDocData.Range(rngStart, rngEnd)
             myRange.Copy
         Forms!FRMIMPORTWORD!frmCENASSplit.SetFocus
         frmCENASSplit!SCENE.SetFocus
         DoCmd.GoToRecord , "", acNewRec
         DoCmd.RunCommand acCmdPaste
             'Dim xyz As String
             'xyz = myRange.Text
             'DoCmd.RunSQL "insert into tblScenes (Scene) values ('" & xyz & "');"
             'Me.frmCENASSplit.Requery
         Else
             Exit Do
         End If
      Loop While idx < 1000
 End With
 End Sub

Open in new window

Regards
Avatar of Armando Vilela Baiões

ASKER

Code still not working on getting the "Scene" header, heres an attached doc
Paula_final_eps11.V1.doc
Import-Word-Doc.accdb
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rgonzo1971 that worked just fine. Thanks a lot!