Page 1 of 1

Help required print merge loop

Posted: Wed Sep 23, 2015 12:22 am
by darylwillis
Hi
Could you help me solve a problem im having. The Program will add data from a array to a pre formated RTF word doc with [[mytnkId1]], [[myDate]], [[ mySite1]], [[myCode1]].
the problem im having is the loop, I can get the first iteration ok to merge and insert from the array, however the second and onwards I need to change the mytnkId1, and myCode1 to be mytnkId2 and so forth, but this is where my troubles start, how can I change mytnkId1 to mytnkId2 as in the preformated docs so I can merge.
I have supplied zip of code
navigate to
Brockman4 - B4 Phase 1 - Print (code)
After that I need to print the generated pages

-- Now to populate the forms from the data in the boxes
local x, check_box, tTemp, mytnkId1, mySite1, myCode1, myDate
put "1138" into check_box -- the first check box to check
put "mySite1" into mySite1
repeat with x=1 to 9
if the hilite button ID check_box is TRUE then -- if its checkbox is checked 1
put "mytnkId" & x into mytnkId1 -- We need to increment the last digit to cycle through all assets
put field myArray[3] into mytnkId1 -- place the Nank number into the right field
put field "myDateField" into myDate -- Date
put "mySite" & x into mySite1
put myArray[2] into mySite1 -- site code
put myArray[2] & " -" & myArray[3] into myCode1 -- Join site and tank id together for func location

end if
put check_box + 1 into check_box -- increment Checkbox check for the next box down

end repeat

Re: Help required print merge loop

Posted: Thu Sep 24, 2015 2:02 am
by darylwillis
Further for simplicity

I want to merge a value into the word document similar to mailmerge.
I use the label mytnkId1 in the document, so to fill that with the data I need I have to use mytnkId1 in my code not the contents of, or the vale of mytnkId1
that said how do I specify in the below line to change mytnkId1
put field myArray[3] into mytnkId1
because if I change mytnkId1 it will not change that in the word document

Re: Help required print merge loop

Posted: Thu Sep 24, 2015 2:21 am
by dunbarx
Hi.

I am not familiar with mailMerge. When you say you have the label "mytnkId1", is that a word or is "label" some form of native object in Word?

I do not fully understand your question. But think about this. If you placed your word document as text into LC, are you asking how to replace the word "mytnkId1" with something else? This is simple, though I suspect it is not what you are looking for.

Do you really have a field named "myArray[3]"? This will not cause a problem, but it is a very strange name for a field. It generally reads as a value in an array variable.

Craig Newman

Re: Help required print merge loop

Posted: Thu Sep 24, 2015 4:53 am
by darylwillis
Hi Dunbarx
within the work doc i have for example Dear [[theName]] your ID is [[mytnkId1]] as the code executes data is inserted,I address those fields as theName and mytnkId1 ect .
put field myArray[3] into mytnkId1
As I loop through the array and change mytnkId1, that is my problem, it has to be the same as the word reference theName or mytnkId1 or whatever
field is un necessary and should be removed (leftover code)

Printing this document

Posted: Thu Sep 24, 2015 8:07 am
by darylwillis
Hi experts
Im very new to livecode and needing help
Im going to try looking at my problem from another angle
attached is a word doc .rtf that I want to print changing the parts within double brackets [[xx]], my initial attempts are not going so well.
I have multiple amounts of data that needs to go into theses fields that could span over 2 or 3 pages then i need to print them all out.
could you help point me in a direction that would achieve that result.
many thanks in advance

Re: Printing this document

Posted: Thu Sep 24, 2015 1:27 pm
by Klaus
Hi Daryl,

please only ONE thread per problem!
This single and lonely RTF file does not make sense per se, I will merge the two postings!


Best

Klaus

Re: Help required print merge loop

Posted: Thu Sep 24, 2015 5:48 pm
by dunbarx
Daryl.

Are you using arrays? I suspect not, and would recommend that you do not use "[" or "]" in your variable names or in the names of fields or other objects. Use instead:

field "yourField"
Dear theName
your ID is mytnkId1

But that leaves the actual problem open.

Say I had the following text: "The quick brown fox jumps over the lazy dog lazy dog lazy dog". Is it just that you want to find all instances of the word "lazy", and substitute the word "mangy"?

"The quick brown fox jumps over the mangy dog mangy dog mangy dog"

Craig

Re: Help required print merge loop

Posted: Thu Sep 24, 2015 10:11 pm
by jacque
darylwillis wrote:Could you help me solve a problem im having. The Program will add data from a array to a pre formated RTF word doc with [[mytnkId1]], [[myDate]], [[ mySite1]], [[myCode1]].
the problem im having is the loop, I can get the first iteration ok to merge and insert from the array, however the second and onwards I need to change the mytnkId1, and myCode1 to be mytnkId2 and so forth, but this is where my troubles start, how can I change mytnkId1 to mytnkId2 as in the preformated docs so I can merge.
The merge command will handle your formatted Word file without altering it. You have the file set up correctly with the double brackets around the variable names. Those should stay unchanged, don't try to alter them within your handler. In your LC handler, create same-named variables and change those values in the loop. Each time through the loop, the merge command will use the new values.

I don't usually download and examine stacks so I haven't seen yours, but here's the general idea:

Code: Select all

repeat for each line tLine in tData -- change this to whatever you want to loop through; array keys, lines of text, etc.
  put "newname" into mytnkid -- replace this example's hard-coded literal to use the values in your array
  put "some date" into myDate
  put "http://www.xxx.com" into mySite
  put "1234" into myCode
  put url ("file:" & tWordFilePath) into tWordDoc -- get the Word doc text from disk, from a property, wherever
  put merge(tWordDoc) into tNewText
  -- do something with it; print, save to file, etc.
end repeat
Each time the loop runs, change the variable values in the first four lines and the merge command will replace them appropriately.

If your Word doc is styled and formatted, you may have better results saving it as RTF or HTML text.

Edit: This is what you're looking for: http://newsletters.livecode.com/novembe ... etter3.php

Re: Help required print merge loop

Posted: Fri Sep 25, 2015 3:27 am
by darylwillis
Thanks all for your help, I had more trouble trying to explain the problem.
jacque I followed that advise and viola it works,
Again thanks for your help all