Jump to content

Mail Merge - Data Source with Variable Length

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Ilikestring

Ilikestring

    Newbie

  • Members
  • PipPip
  • 17 posts
Hello, I am attempting to get my program to print out letters that will be sent to students informing them of their appointment times.
However, since a student can have any number of appointments I can not simply specify how long the Data Source is.
A typical Data Source creation would look like this:

 wrdDoc.MailMerge.CreateDataSource('C:\DataDoc.doc',,,'FirstName, LastName,' +

       ' Address, PostCode');

How could I use a FOR loop to add extra fields?
Something like:

wrdDoc.MailMerge.CreateDataSource('C:\DataDoc.doc',,,'FirstName, LastName,' +

       ' Address, PostCode + FOR Count := 1 to WhateverLengthIneed do 'Appointment' + IntToStr(Count));

Of course that doesn't work for me.
What will work? :crying:

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What is the structure of your source document?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Ilikestring

Ilikestring

    Newbie

  • Members
  • PipPip
  • 17 posts
I'm not quite sure what you mean.
The code at the top would create a Data Source that looks like this:

Posted Image

And with entries:

Posted Image

Is that what you were asking?

At run time students could have any number of appointments, so I need to make my program be able to vary as to how many extra columns it could put in the data source regarding each appointment, but I have no idea how to do that.

#4
Ilikestring

Ilikestring

    Newbie

  • Members
  • PipPip
  • 17 posts
Nobody knows what I can do? :crying:

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You still haven't really specified a data structure. Is it tab delimited, something else?

I wouldn't use Word as the source data format if I could help it. Excel or Access would be much better.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
Firebird_38

Firebird_38

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Sometimes you should consider trying to add another line or two. For loops don't go inside function calls. They do, however, work outside function calls as their very own statement. Programming 101.

 
var extrafields,fieldname:string;
     n:Integer;
..
begin
..
extra:='';
for n:=0 to FieldCount-1 do
 begin
  fieldname:='Appointment' + IntToStr(n); //change to whatever you need
  extrafields:=extrafields+','+FieldName;
 end;
 wrdDoc.MailMerge.CreateDataSource('C:\DataDoc.doc',,,'FirstName, LastName,' +
       ' Address, PostCode'+[B]extrafields[/B]);
 
..
end;
..

Easy as pie.