vba - Saving a Word File from Mailmerge with Data Base Field Name as the File Name -


i able save active file in word 2010 mailmerge, file name derived database field "first_name" , database field "last_name" subfolder hardcoded subfolder.

i receive error "requested member of collection not exist".

i know error occurs when try access object not exist. data base field first_name, , have tried first name in case code searching address field of first name, has been paired data base field of first_name. here have tried:

sub savingindividuallybycustomername()  dim firstname string dim lastname string  firstname = activedocument.formfields("first_name").result lastname = activedocument.formfields("last_name").result      activedocument.mailmerge     .destination = wdsendtonewdocument     .suppressblanklines = true     .datasource         .firstrecord = activedocument.mailmerge.datasource.activerecord         .lastrecord = activedocument.mailmerge.datasource.activerecord     end     .execute pause:=false end changefileopendirectory "c:\folder\subfolder\subsubfolder\"    activedocument.saveas2 filename:= _         "c:\folder\subfolder\subsubfolder\" & firstname & lastname & ".docx" end sub 

when hardcoded name with

firstname = "john" lastname = "doe" 

i had no other errors , active file saved.

i attempted use without success:

dim firstname field dim lastname field 

instead of

firstname = activedocument.formfields("first_name").result  lastname = activedocument.formfields("last_name").result 

you need

firstname = activedocument.mailmerge.datasource.datafields("first_name").value  lastname = activedocument.mailmerge.datasource.datafields("last_name").value 

the name in quotes case-sensitive (unusual in windows programming). has match name word using, may not identical 1 in data source.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -