PDA

View Full Version : How to get a listbox to populate from Mailmerge field?



britneyirv
03-28-2016, 12:38 PM
Hello all,
I am new to this forum, well new to posting at least; so if I happen to break any rules, let me know and it won't happen again.

I currently have a huge project of automation I am working on for an accounting firm. I will give a quick explanantion so you all understand the background.

- Excel file for certain #s pertaining to a company that is then put into a graph.
- Button in said Excel file to copy certain graph and post to a Word doc.
- That Word doc consits of a letter that opens at a bookmark to insert the graph.
- Userform pops up & user fills in certain data (Company code, date, quarter or month report)
- After filling out the userform populates certain bookmarks with the information given
- Word doc also has a mail merge list already loaded in
- I want to be able to select a certain mail merge option with a box the user fills in on userform and then make that the active record and fill in the merge fields..


Private Sub CommandButton1_Click()Dim dsMain As MailMergeDataSource
Dim numRecord As Integer


ThisDocument.MailMerge.ViewMailMergeFieldCodes = False
Set dsMain = ThisDocument.MailMerge.DataSource
If dsMain.FindRecord(FindText:=CompanyCode.Text, _
Field:="Company Code") = True Then
numRecord = dsMain.ActiveRecord


End If
Unload Me
End Sub



CompanyCode.Text is my text box where they will input the company code which can be found in the mail merge

The issue is code runs all the way through no issues, but it never actually selects the mail merge record that I want active.

Thank you.

gmayor
03-28-2016, 09:27 PM
If you want this to be a mail merge, then see http://www.gmayor.com/mail_merge_charts.htm which could save you a lot of time and effort.
If however you are creating documents individually, I would abandon the mail merge approach altogether and simply send data from the selected record directly from the workbook to the document, using bookmarks or docvariables from your Excel macro.