Export to word and multiple word document

DevAccess

Registered User.
Local time
Today, 05:29
Joined
Jun 27, 2016
Messages
321
Hello

I have been developing a resume builder database and based on criteria resume is being exported to word, exporting vba code as below what I see problem is that when there are two matching records found means two candidate resume should be exported to word, but when first export is finished the word writes few information of the second word document to first opened word document ( i.e resume record ) wherin ther is use of SELECT statment as stated below :

I am using wdapp.visible = false which keeps open the entire word document

here is the code of select which keeps overriding to one.

Code:
If rsGetPosition.RecordCount <> 0 Then
                While Not rsGetPosition.EOF
                composite = "a) Company = " & rsGetPosition.Fields("Company Name").Value & vbCrLf
                 ActiveDocument.Tables(1).Cell(8, 1).Select
                  'Move to the right
                  Selection.Collapse Direction:=wdCollapseEnd
                  'Move back to the left
                  Selection.MoveLeft wdCharacter, 1
                  'Add the text (using the myText1 format)
                    Selection.Range.Text = composite
                  'Select the on word the right (myText2)
                  Selection.MoveRight Unit:=wdWord, Count:=Len("a) Company = " & rsGetPosition.Fields("Company Name").Value), Extend:=wdMove
                'Format myText2
                  Selection.Range.Font.Underline = False
                  Selection.Range.Font.Bold = False
                  Selection.Range.Font.Size = 12
                  composite = ""
                  
                  composite = "b) Position = " & rsGetPosition.Fields("Position").Value & vbCrLf
                 ActiveDocument.Tables(1).Cell(8, 1).Select
                  'Move to the right
                  Selection.Collapse Direction:=wdCollapseEnd
                  'Move back to the left
                  Selection.MoveLeft wdCharacter, 1
                  'Add the text (using the myText1 format)
                    Selection.Range.Text = composite
                  'Select the on word the right (myText2)
                  Selection.MoveRight Unit:=wdWord, Count:=Len("a) Position = " & rsGetPosition.Fields("Position").Value), Extend:=wdMove
                'Format myText2
                  Selection.Range.Font.Underline = False
                  Selection.Range.Font.Bold = False
                  Selection.Range.Font.Size = 12
                  composite = ""
                  
                  
                   composite = "c) Dates = " & rsGetPosition.Fields("Date").Value & vbCrLf
                   ActiveDocument.Tables(1).Cell(8, 1).Select
                  'Move to the right
                  Selection.Collapse Direction:=wdCollapseEnd
                  'Move back to the left
                  Selection.MoveLeft wdCharacter, 1
                  'Add the text (using the myText1 format)
                    Selection.Range.Text = composite
                  'Select the on word the right (myText2)
                  Selection.MoveRight Unit:=wdWord, Count:=Len("c) Dates = " & rsGetPosition.Fields("Position").Value), Extend:=wdMove
                'Format myText2
                  Selection.Range.Font.Underline = False
                  Selection.Range.Font.Bold = False
                  Selection.Range.Font.Size = 12
                  composite = ""
                  
                  
                   composite = "d) Serves As = " & rsGetPosition.Fields("Serves As").Value & vbCrLf
                   ActiveDocument.Tables(1).Cell(8, 1).Select
                  'Move to the right
                  Selection.Collapse Direction:=wdCollapseEnd
                  'Move back to the left
                  Selection.MoveLeft wdCharacter, 1
                  'Add the text (using the myText1 format)
                    Selection.Range.Text = composite
                  'Select the on word the right (myText2)
                  Selection.MoveRight Unit:=wdWord, Count:=Len("d) Serves As = " & rsGetPosition.Fields("Serves As").Value), Extend:=wdMove
                'Format myText2
                  Selection.Range.Font.Underline = False
                  Selection.Range.Font.Bold = False
                  Selection.Range.Font.Size = 12
                   composite = ""
                  
                  
                   composite = "e) Currently Supervies = " & rsGetPosition.Fields("Currently Supervies").Value & vbCrLf
                   ActiveDocument.Tables(1).Cell(8, 1).Select
                  'Move to the right
                  Selection.Collapse Direction:=wdCollapseEnd
                  'Move back to the left
                  Selection.MoveLeft wdCharacter, 1
                  'Add the text (using the myText1 format)
                    Selection.Range.Text = composite
                  'Select the on word the right (myText2)
                  Selection.MoveRight Unit:=wdWord, Count:=Len("e) Currently Supervies = " & rsGetPosition.Fields("Currently Supervies").Value), Extend:=wdMove
                'Format myText2
                  Selection.Range.Font.Underline = False
                  Selection.Range.Font.Bold = False
                  Selection.Range.Font.Size = 12
                  
                  
                    rsGetPosition.MoveNext
                Wend
              End If

I am printing multiple text in one cell of table of word with different formating like Bold,italic ..
 
Last edited:
Something not actually shown in this code is your culprit. We cannot see file manipulation, only file content manipulation in the code snippet.

You have a loop that starts with an ActiveDocument reference, which means that the Word file manipulation (word.Document.Open) must occur outside of this loop. You get the file you want, so that must be OK. However, nowhere inside the loop that you showed us do you do anything to change which document is active.

The reason you add data to the first document is that you never close it and open a new document inside your loop. At the point where you do a .MoveNext for your recordset, you would need to add code to close the active document. At the top of your loop, just after your recordset .EOF test, you should open another document to make IT active.
 
Something not actually shown in this code is your culprit. We cannot see file manipulation, only file content manipulation in the code snippet.

You have a loop that starts with an ActiveDocument reference, which means that the Word file manipulation (word.Document.Open) must occur outside of this loop. You get the file you want, so that must be OK. However, nowhere inside the loop that you showed us do you do anything to change which document is active.

The reason you add data to the first document is that you never close it and open a new document inside your loop. At the point where you do a .MoveNext for your recordset, you would need to add code to close the active document. At the top of your loop, just after your recordset .EOF test, you should open another document to make IT active.

Thanks for your response, however as per our requirement I can not close the active document all the export to word which has been generated as per search criteria should open, for example if there are 10 matching candidates 10 word documents (resumes ) should be open at the end of the operations.
 

Users who are viewing this thread

Back
Top Bottom