Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Opening an Existing Word Document"

Opening an Existing Word Document

...and adding fields into it.

Current user: [none]
Register / Log In · Help

Posted By Post

Voices4Wellbeing

22-Oct-2010 14:40

I have a new database that records issues and comments recieved from the general public.

If people give us their contact details we send them a standard letter of aknowledgement. I want a macro that opens this document (let's call it letter.doc), and then inserts the following fields in the appropriate places (name, address, post code).

Is this possible?

bert

22-Oct-2010 15:38

I would say: Of course is this possible.

Three ways:
1. A Cardbox macro which opens the doc and insert the right values on right place
2. In Word a macro that get the values of the current doc and place it on the right place
3. The easiest way: First copy a Cardbox field. Then paste this on the right place in your Word doc as a link (paste special). In word then you add a DDE field.
You will see that when you browse to another record in Cardbox, the values in Word also are changed.
Because you make dynamic links however, you can only archive such a file when you convert the link to values in your doc and save it as file xyz.doc

I prefer option 1. Cardbox macros are easier to store and handle than Word macro's (safety levels etc..).
However, you need some experience programming such a macro. Or buy it somewhere. I helped some companies with such a thing.

regards
Bert

Mary Doyle

23-Oct-2010 08:34

There is an alternative to using Word. You could design an alternative format in Cardbox with the same text and layout as you have in the Word document, using merge blocks. Your merge blocks would have field references where appropriate. If you have an electronic copy of your logo it could be incorporated as a page heading, or you could set the print settings of the format to print to the printer or printer tray that holds your headed notepaper. If you have an email address for your contact you might consider sending them a standard email instead. At work we use one or other of the above methods and never use Word for standard letters. The process of issuing the letter or email is usually automated with macros, but that is not essential.
As they say "there is more that one way to skin a cat"!

bert

23-Oct-2010 12:05

Hi Mary,
Of course, your suggestion also can be a solution. However, that was not the question, so I did not mention it.
Using this suggestion also you need to do extra things for archiving by printing also to pdf or so if (needed of course).
Also there are limitations in Cardbox formats. I met several situations where Cardbox formats could not make the specified layout.
It's also puzzling. Especially when automatic height in merge blocks is used.
Although I am not a big fan of MS Word, it gives much more possibilities generating reports or fill forms with Cardbox data in a layout exactly as you want to get.
regards

Mary Doyle

23-Oct-2010 12:59

Hi Bert,
Yes, I do realise my answer was not an answer to the question - I was just throwing it out as an alternative approach that I have found works in my situation, though a little niggle at the back of my mind said "you will probably be told you are not actually answering the question!". I read your response with interest, as I have not had reason to take this approach, but I can see that if a layout is particularly complicated it could be very useful. I have stored it up for future reference.
All the best
Mary

Voices4Wellbeing

26-Oct-2010 14:55

Thank you. I will try a couple of those and see how it works out. I'm currently testing the new format one, because that seems like the best fit.

Voices4Wellbeing

27-Oct-2010 08:53

I tried your idea Mary, and it works great. I thought I would expand it a little, so that you press a button and it prints the letter from the 'letter' format, then returns to the native format, clicks a yes checkbox in a field, and also adds a date in a seperate field.

I managed the checkbox ok, as I can just record that. But I am struggling with the date. I have read some other threads on here and tried to do it myself, but I am not getting it right.

My macros currently reads:

Format="letter"
Print cbxPrintMainRecord,,RecordPosition,RecordPosition
Format=""
EditRecord
GoToField "YESNO5"
SetOption 0,True
Fields("DATESENT") = DatetoCardbox
SaveRecord

Could anyone help me with the date section? I just need it to add todays date when the letter is sent. But without it changing to todays date if the record is opened/edited again (unless of course someone runs the macro again).

Charles Welling

27-Oct-2010 10:20

You've obviously consulted the help file on macros, seeing that you are aware of "DatetoCardbox". The same section of the Help file gives you the answer: the word to use is "Now".

Fields("DATESENT") = DatetoCardbox(Now,".")

would return "2010.10.27"

Read the section again to see what the "." does.

Voices4Wellbeing

27-Oct-2010 11:21

Thank you. I actually got the 'DatetoCardbox' from another thread on this forum, but that one was to add 21 days to a date. I was trying to fudge my own version from that.

Thanks again.

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home