P
Peter Hibbs
I am using Word 2003 and Access 2003.
I have written a database which uses Automation to change specific
text groups in a Word document. For example, in the Word document I
have a number of special control codes like [CLN] and [CLI] and [CAD]
and so on which would represent fields in the database table for
Client Last Name, Client Initials, Client Address, etc. What happens
is that the end user creates a sort of template Word document (similar
to a Mail merge doc) and he embeds these control codes in the text of
the document. Something like :-
Dear [CLI] [CLN],
etc, etc.
Then in the database he opens a client record, clicks a button, and my
database code opens Word, creates a new document and then uses the
Word ReplaceWith command to copy the contents of various fields in the
database record into the relevant control code positions in the
document. The code snippet is like -
obj.ActiveDocument.Content.Find.Execute FindText:=vSource, _
ReplaceWith:=vDest, Format:=True, _
Replace:=wdReplaceAll
Obviously this bit of code is repeated for each field in the table and
each control code in the document.
This all works fine.
My problem is now that the user wants to change the text that appears
in the document depending on the value in the database field. So for
example, if the database field called Premium (a Currency type) is
copied to a control code called [PRE] it would show in the document
(after the ReplaceWith has completed) as £123.45 (or whatever) and if
it was 0 in the database table it would show as £0.00.
What the user wants is that if the result of the ReplaceWith operation
is £0.00, he wants to show some text instead of the zero amount, lets
say 'No Premium required' or whatever. Of course, this could be done
within the database code but this would mean that the user would not
be able to change it easily.
What I would like is, if it is possible, to use some sort of Word
Field Code function to check what the result of the ReplaceWith
operation was and if it was 0 or £0.00 (whichever is appropriate) it
would show some user defined text in the document and if it was NOT 0
it would show the actual amount.
I have tried a few things but I can't seem to find the right syntax
(if it is even possible). Does anyone know if/how it can be done.
Peter Hibbs.
I have written a database which uses Automation to change specific
text groups in a Word document. For example, in the Word document I
have a number of special control codes like [CLN] and [CLI] and [CAD]
and so on which would represent fields in the database table for
Client Last Name, Client Initials, Client Address, etc. What happens
is that the end user creates a sort of template Word document (similar
to a Mail merge doc) and he embeds these control codes in the text of
the document. Something like :-
Dear [CLI] [CLN],
etc, etc.
Then in the database he opens a client record, clicks a button, and my
database code opens Word, creates a new document and then uses the
Word ReplaceWith command to copy the contents of various fields in the
database record into the relevant control code positions in the
document. The code snippet is like -
obj.ActiveDocument.Content.Find.Execute FindText:=vSource, _
ReplaceWith:=vDest, Format:=True, _
Replace:=wdReplaceAll
Obviously this bit of code is repeated for each field in the table and
each control code in the document.
This all works fine.
My problem is now that the user wants to change the text that appears
in the document depending on the value in the database field. So for
example, if the database field called Premium (a Currency type) is
copied to a control code called [PRE] it would show in the document
(after the ReplaceWith has completed) as £123.45 (or whatever) and if
it was 0 in the database table it would show as £0.00.
What the user wants is that if the result of the ReplaceWith operation
is £0.00, he wants to show some text instead of the zero amount, lets
say 'No Premium required' or whatever. Of course, this could be done
within the database code but this would mean that the user would not
be able to change it easily.
What I would like is, if it is possible, to use some sort of Word
Field Code function to check what the result of the ReplaceWith
operation was and if it was 0 or £0.00 (whichever is appropriate) it
would show some user defined text in the document and if it was NOT 0
it would show the actual amount.
I have tried a few things but I can't seem to find the right syntax
(if it is even possible). Does anyone know if/how it can be done.
Peter Hibbs.