mailmerge - How Can I Limit an .OpenDataSource in Word Mail Merge to Only 1 Record Using VBA? -


word 2013, sql server 2014 have word mail merge template created licensing application uses .ini file , excel file generate 1 certificate dataset of many.

i want make word template work on it's own. able wire .udl file make connection database gives me tables, pick one, gives me document each row in table when need one.

how can limit/filter document comes template use specific table , specific row (license_id) request?

sub autonew()  'this returns rows after pick table thisdocument.mailmerge     .opendatasource name:="c:\users\or0146575\desktop\xxx.udl"     .execute end  end sub 

i wire below code return 1 row if knew how.

dim sql string  sql = "select full_name, biglicensetype, licnosdisplay, expiration_date opcerts person_id= 30012" 

i decided take totally different route , hope doesn't detract points.

using datasource file .udl or .odc bringing records , required selecting table @ runtime , couldn't sql work.

i decided make connection old adodb (microsoft activex data objects 2.5 library in tools > references) , assign values mailmerge fields or docvariable fields or bookmarks, ever work. no sense in using mailmerge 1 record. hope helps someone.

sub autonew()  dim strwhat string  strwhat = inputbox("enter license id", "opcert wall certificate")   dim conn adodb.connection dim cmd adodb.command set conn = new adodb.connection conn.connectionstring = "provider=sqloledb.1;integrated security=sspi;persist security info=true;initial catalog=dws_licenses;data source=wpdhsclr16c"  conn.open  set cmd = new adodb.command cmd.activeconnection = conn cmd.commandtext = "select full_name, biglicensetype, licnosdisplay, expiration_date opcerts person_id=" & cint(strwhat)   dim rs adodb.recordset set rs = cmd.execute() 'execute stored procedure.  'this changed bookmark(s) if docvariables doesn't work activedocument.variables("expiration_date").value = rs(3) 'put full_name, biglicensetype, licnosdisplay tags here  rs.close  set rs = nothing  set cmd = nothing conn.close set conn = nothing  end sub 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -