Albert Kallal's word merge

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to build this into my database - thanks very much for your help
Mr Kallal - and I cannot work out how to link it to a query.

I am working on a copy of my database in 'My documents 3' and trying to
merge MEMART.doc to query IncorporationQuery. I have put:

MergeNoPrompts "MEMART", "c:my documents 3\word\", True, ,
"IncorporationQuery"

I get message
"No data was created for this merge
Make sure the sql is correct
The sql was IncorporationQuery"

What am I doing wrong?

Thanks
Dudley
 
MergeNoPrompts "MEMART", "c:my documents 3\word\", True, ,
"IncorporationQuery"

That looks ok. Can you close all forms, and simply run the IncorporatonQuery
by its self?

That query need to be clean sql, and should not have nay promtps
(parameters), or even references to open forms

If you need some type of where clause...build it in your code....

strSql = "select * from IncorporationQuery where city = 'Edmonton'"

MergeNoPrompts "MEMART", "c:my documents 3\word\", True, , strSql

So, try running the query all by its self by just clicking on the
query......does the query work?
 
The query works fine with no forms open. The sql is

SELECT Incorporation.*, "DM" & [EnvelopeNumber] & ".MEM" AS FileName,
[Shareholder1ShareNumber]+[Shareholder2ShareNumber]+[Shareholder3ShareNumber]+[Shareholder4ShareNumber]
AS TotalIssuedShares, Format([EnvelopeCreationDate],'d mmmm yyyy') AS
LongDate, IIf(([Shareholder2ShareNumber]>0),([Shareholder2ShareNumber])) AS
Share2Shares, IIf(([Shareholder3ShareNumber]>0),([Shareholder3ShareNumber]))
AS Share3Shares,
IIf(([Shareholder4ShareNumber]>0),([Shareholder4ShareNumber])) AS
Share4Shares, IIf(IsNull([SecisDir]),([SecretaryFirstForename])) AS
SecNotDirFirstForeName, IIf(IsNull([SecisDir]),([SecretaryOtherForenames]))
AS SecNotDirOtherForeNames, IIf(IsNull([SecisDir]),([SecretarySurname])) AS
SecNotDirSurname, Right([EnvelopeNumber]+1000000,6) AS Envelope,
Format([AuthorisedCapital],'Standard') AS MemAuthCapital,
Format([ShareNumber],'#,##0') AS MemShareNo,
Format([EnvelopeCreationDate],'ddmmyyyy') AS EmailDate,
Format([EnvelopeCreationTime],'hhnnss') AS EmailTime,
Format([ShareValue],'Standard') AS MemShareValue,
Format(([Shareholder1ShareNumber]+[Shareholder2ShareNumber]+[Shareholder3ShareNumber]+[Shareholder4ShareNumber]),'#,##0')
AS MemTotalIssuedShares, Format([Shareholder1ShareNumber],'#,##0') AS MemSh1,
IIf(([Shareholder2ShareNumber]>0),Format([Shareholder2ShareNumber],'#,##0'))
AS MemShare2Shares,
IIf(([Shareholder3ShareNumber]>0),Format([Shareholder3ShareNumber],'#,##0'))
AS MemShare3Shares,
IIf(([Shareholder4ShareNumber]>0),Format([Shareholder4ShareNumber],'#,##0'))
AS MemShare4Shares, Left([IncorporationDate],1) AS PartDate1,
Mid([IncorporationDate],2,1) AS PartDate2, Mid([IncorporationDate],4,1) AS
PartDate3, Mid([IncorporationDate],5,1) AS PartDate4,
Mid([IncorporationDate],7,1) AS PartDate5, Mid([IncorporationDate],8,1) AS
PartDate6, Mid([IncorporationDate],9,1) AS PartDate7,
Mid([IncorporationDate],10,1) AS PartDate8, Format([IncorporationDate],'d
mmmm yyyy') AS IncorpLongDate, IIf(Not
IsNull([Shareholder2Surname]),([IncorporationDate])) AS Shareholder2Date,
IIf(Not IsNull([Shareholder3Surname]),([IncorporationDate])) AS
Shareholder3Date, IIf(Not
IsNull([Shareholder4Surname]),([IncorporationDate])) AS Shareholder4Date,
IIf(Not
IsNull([Shareholder2Surname]),Format([Shareholder1ShareNumber]+1,'#,##0')) AS
Share2Start, IIf(Not
IsNull([Shareholder3Surname]),Format([Shareholder1ShareNumber]+[Shareholder2ShareNumber]+1,'#,##0'))
AS Share3Start, IIf(Not
IsNull([Shareholder4Surname]),Format([Shareholder1ShareNumber]+[Shareholder2ShareNumber]+[Shareholder3ShareNumber]+1,'#,##0'))
AS Share4Start, IIf(Not
IsNull([Shareholder2Surname]),Format([shareholder1ShareNumber]+[Shareholder2ShareNumber],'#,##0'))
AS Share2End, IIf(Not
IsNull([Shareholder3Surname]),Format([Shareholder1ShareNumber]+[Shareholder2ShareNumber]+[Shareholder3ShareNumber],'#,##0'))
AS Share3End, IIf(Not
IsNull([Shareholder4Surname]),Format([Shareholder1ShareNumber]+[Shareholder2ShareNumber]+[Shareholder3ShareNumber]+[Shareholder4ShareNumber],'#,##0'))
AS Share4End, IIf(Not IsNull([Director1DOB]),Left([Director1DOB],2) & "/" &
Mid([Director1DOB],3,2) & "/" & Mid([Director1DOB],5,4)) AS Dir1DOB, IIf(Not
IsNull([Director2DOB]),Left([Director2DOB],2) & "/" & Mid([Director2DOB],3,2)
& "/" & Mid([Director2DOB],5,4)) AS Dir2DOB, IIf(Not
IsNull([Director3DOB]),Left([Director3DOB],2) & "/" & Mid([Director3DOB],3,2)
& "/" & Mid([Director3DOB],5,4)) AS Dir3DOB, IIf(Not
IsNull([Director4DOB]),Left([Director4DOB],2) & "/" & Mid([Director4DOB],3,2)
& "/" & Mid([Director4DOB],5,4)) AS Dir4DOB
FROM Incorporation;

Is there anything in it which would cause a problem?

Thanks very much for your help.
Dudley
 
Hum, in my sample word merge, there is a sample form that lets you select a
query from a combo box. Try importing that form into your current
application, and run that form. ...can you select this query..and run it?

You could also test this by going

...... open up a new code module and go

sub mytest

dim rst as dao.recordset

set rst = currentdb.openreocrdset("IncorporationQuery")

rst.movelast

msgbox "number of reocrds in query = " & rst.recordcount

end sub

Can you run the above code in a test module.?

Somting is not right...I just don't know what.....
 
The combo box query does run, but it produces a document for all records. I
have found a way round the problem. I created a form based on the query and
started from scratch so that merge.888 was created on the query fields
instead of the table ones. Then MergNoPrompts "MEMART" works fine.

Thanks very much for all your help.
Dudley
 
I have now found another problem. I solved the original problem by changing
the source of the form to be the same query as the source of the Word
template, but this does not help when I want to run Wordmerge on a template
based on a different query. So far as I can see the problem is that it does
not help using the switch for a different query as the merge.888 file is
still based on the fields in the form. What is the solution? Do I need to
create a new form for each query and then open this form before running
wordmerge for the template which uses this query?

Thanks for all your help and sorry to keep bothering you.

Regards
Dudley
 
The combo box query does run, but it produces a document for all records.

Well, in your sample query, there was no "where" clause, so why would you
expect to get any thing else then all records? I saw no restrictions or even
a where clause in your query you posted...so for what reason would you
expect NOT TO have all records returned?

We are obviously missing (you leaving out) a VERY important detail here....

In that sample form that displays all queires...the form itsself is UN-BOUND
and
is NOT attahced to any table...so, how would any restrucitons occur based on
you
selecting a query from a comb box?

(again, I am very very confused here now...).

So far as I can see the problem is that it does
not help using the switch for a different query as the merge.888 file is
still based on the fields in the form

Hum, that is not the way it is supposed to work. If you supply the optional
sql, then the fields will be based on the sql supplied..not the forms
fields....
(in fact, how could that sample form with the the combo box forqueries work
on all diffent tables then....ESPCEIALLY WHEN the form is not BOUND to any
table!!!).

It is possible your come across some bug here, but, for the most part you
should not had to base the form on the query to make this work in the first
place...

We also do need to clear up why you expect reocrds to be restricted to a
particlar set of reocrds when you sql says to return all roecrds?
Are you trying to use sql...but STILL ONLY return the one reocrd?

Remember, it goes without saying that if you supply your own sql..then you
must supply which reocrds that sql will use....

I mean, if the above was not the case, then how could we EVER do a merge to
all people in a given city? The obfvilsry answer here is that YOU supply the
restrctions when you do this...

So, you need to supply your restrcitons your self when you supply the
sql...

So, if we were on a form, but wanted to send the ONE reocrd to the merge,
but use a query, then we would go
eg:

strSql = "select * from Incorporation where id = " & me!id

MergeSingleWord strSql

Or, in your case...

MergeNoPrompts "overdue.doc",,,,strSql

Does all of your code compile ok?


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.members.shaw.ca/AlbertKallal

If you don't supply the sql, then the fomrs fields are used.....
 
I am sorry that I have confused you by my limited knowledge and unclear
statements, but it has been extremely useful to me and I would like to thank
you very much. I have now written code which opens the wordmerge doc, writes
it to file and exits back to the form without any problems. There is a slight
problem with my code that I have to exit out of Access before running it
again as otherwise running it a second time the ActivePrinter is not
recognised.

Another minor problem is that importing your wordmerge into my database,
when I run it it opens a second copy of Access (which does not of course
happen in your test database), and the same happens even if I just run
MergeNoPrompts "mydoc".

When I run 'MergeNoPrompts "mydoc",,,,"strQuery"' the computer locks up and
I have to turn it off at the plug. Maybe this is due to inadequate memory and
I will not have the same problem when I run it on a more powerful computer.

The code which works to write to file is:

Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")

Dim PrnDocName As String
PrnDocName = "c:\my documents 2\word
documents\electronicincorporation\memarts\DM" & _
Me![EnvelopeNumber] & ".MEM"

MergeNoPrompts "MEMART", "C:\My documents 2\access documents\word", True

If Len(Dir$(PrnDocName)) > 0 Then
SetAttr PrnDocName, vbNormal
Kill PrnDocName
End If

ActivePrinter = "HP LaserJet IIP"
objWord.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="2-20", PageType:= _
wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True,
Background:= _
True, PrintToFile:=True, PrintZoomColumn:=0, PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0,
OutputFileName:=PrnDocName, _
Append:=False
ActiveDocument.Close (wdDoNotSaveChanges)
objWord.Quit

Thanks again for all your help.
Dudley
 
Another minor problem is that importing your wordmerge into my database,
when I run it it opens a second copy of Access (

On a test form, place a button, and go

MergeAllWord "IncorporationQuery", _
"C:\My documents 2\access documents\word", _
True

Then open that word document by using the "modify the template" button.

Now, close the word document....note how you are prompted to save the
template..but DID NOT modify anything?

The reason why you are asked to save is that my merge code has re-set the
data source of
that word document to the text file, and NOT the mdb file.

The only reason why a 2nd copy of ms-access sis being launched is either

a) due to you writing more word code
b) using a word template that has not been created by my software

The 2nd problem above might sound confusing, but the fix is
to try the Edit the word
template using my software as I state above. My software will then setup the
word documents connection to the text file that my merge software creates
and uses. When you save the template, then the word document is now
attached to the text file..and NOT the mdb file....

So, it is actually word that is launching the 2nd copy of ms-access, not my
software. My software is designed to specially fix this problem by NOT
attached to the mdb file. Of course, my software can only make this change
to the word document if you actually open, and edit the word document using
my software menu option. "modify the template" button.
When I run 'MergeNoPrompts "mydoc",,,,"strQuery"' the computer locks up

As mentioned, try modifying the document with my software first.

Further, then try doing the merge with the menu system I built....and NOT
your code....

Get the merge working....and then..try to get the merge no prompts..and your
eventual print working.

Break this down into steps...get one thing working..and one step.at a
time...

ONLY THEN DO YOU WANT to attempt using the merge code without any prompts.

So, keep in mind, to use my word merge examples, you MUST use my interface
to create the word merge document. The key piece of information here is
that my software sets the word merge to a text file, and NEVER EVER lets the
word document attach to the actual mdb file (this is just rife with many
problems...one of which is word launching a 2nd copy of ms-access). I
explain more about this concept here....

http://www.members.shaw.ca/AlbertKallal/wordmerge/page2.html

*please* Take a Read of the above paragraph called
"Don't let word attached to you running mdb file. "

The code which works to write to file is:

Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")

I would suggest that you let my merge code complete finish...and THEN start
your code to createobject the word....and print it...

You thus *should* test this system with one line of code such as
MergeNoPrompts "MEMART", "C:\My documents 2\access documents\word", True

In fact, just reading the above line you used, the data will be based on
your form, and I think
it would be better to supply the sql to the above...

My software launches word...creates the document..and sets the focus to
the word document. At this point, do you want to allow the user to edit the
document, or do you just care to print it?

Out of a good idea, I have *just* added the ability for mergenoprmpts to
print a document, and also lets you choose what printer.

So, you can no go

dim PrnDocName as string
dim strSql as string

strSql = "select * from Incorporation where id = " & me!id

' the above will restrict the sql to the records you want. Obviously, you
can/will modify the above criteria to YOUR NEEDS.


PrnDocName = "c:\my documents 2\word
documents\electronicincorporation\memarts\DM" & _
Me![EnvelopeNumber] & ".MEM"

Can I assume that the above is the output file name you want to create as a
result of the merge?

If yes, then:

MergeNoPrompts "MEMART", _
"C:\My documents 2\access documents\word", True, _
PrnDocName, _
strSql, _
True

Note the new last option set as true. (this will have my code print the
document for you)

And, you can even set the printer to send it to, such as

MergeNoPrompts "MEMART", _
"C:\My documents 2\access documents\word", True, _
PrnDocName, _
strSql, _
True, _
"\\HCS-466\HP DeskJet 812C"

The above does not change, or touch your default printer...
(leave that pritner settng blank if you want the default printer)

I also notice that you have not given the output document a name in your
sample....

However, you can now use the above to do this...

Remember, my merge code does not NOT wait for the user.
So, if you need to print the docuemnt *AND* allow the user to
edit the resutling document, you will have to train users to print, or
create
a 2nd buttion to print the document after they done the editing of the
merged docuemnt.

However, If you just need to print the docuemnt
and save it with a name, then the above code modifications I
did will do the trick.

At least with the above new feature, you can now print..and the output
document is saved
to whatever document you want (in the above example...PrnDocName).
MergeNoPrompts "MEMART", "C:\My documents 2\access documents\word", True

Also, MergeNoPrmpts has the ability to sned the results to a docuemtn name
of your choice, perhaps you should use that feature?

Also, your code example does a word merge, deletes the word document, but
you do not give the word document a name with your code example. I have to
assume the end ensure supplies the word document name, or do you just
discard it? You also risk printing the wrong word document here, as
another document might be opened already?

I note that you do set

PrnDocName = ......

Yet, your code does not attempt to open the above prndocname with my code..
(it does however kill the document).

Do you perhaps just need to print..and NOT save the document?
(if yes..then DO NOT supply the output document for MergeNoPrompts, but set
print = true....my code will DISCARD the output document after it prints
*if* you do not supply a output document name).

And, while we are at this...for what reason do you have a SetAttr command?

Anyway, just delete the two code modules for word merge..and
re-import my new version I just posted.
example. The mergenoprompts can now print. So, the whole process should now
only take you 3 lines of code as above....

You can find it in the same old place...

http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html
 
Many thanks for all your help. I am very grateful that you have taken so much
trouble.

The second copy of Access problem was of course my fault. I carefully read
what you said on the subject but still did not follow your advice to paste
into your template instead of copying my own template.

Computer locking up when MergeNoPrompts...strQuery is run - I have found
that this is (if I have got it right) because when MergeNoPrompts is run on a
query it selects all records. Putting in select sql solves the problem.

I have however found a new problem with the print file. I do electronic
incorporation, and the specs require that I produce a print file in PCL5
(which is why I have to change the printer as my default is a PCL6 printer),
with the suffix .mem instead of prn. So far as I can see:

1. All print files I create through Access code print as gibberish.
2. If I open the word doc and print to file manually as DM1234.MEM it is
saved as DM1234.MEM.prn.
3. If I print manually to file as "DM1234.MEM" it saves and prints
perfectly. This is how I am doing it now (partly with a Word macro) and it
seems I will have to keep this part of my old system.

Thanks again for all your help. Opening the Memorandum and Articles document
through your wordmerge will cut down the work, and also the scope for errors
when manually finding the correct record through mailmerge.

By the way you asked why I have a SetAttr command. I put in the kill code so
that if the user finds an error and needs to re-do he can kill the old print
doc, and looking up the best way to do this I found an article on the MVP
website (co-author Doug Steele). Their code includes the SetAttr command to
normal as the kill command does not work with read only files. I could not
see how my file could be read only but I thought I might as well keep it in.

Code is
Dim strSql As String
strSql = "select * from IncorporationQuery where EnvelopeNumber = " &
Me!EnvelopeNumber
MergeNoPrompts "MEMART", , , , strSql

Dim PrnDocName As String
PrnDocName = "c:\my documents 2\word
documents\electronicincorporation\memarts\DM" & _
Me![EnvelopeNumber] & ".MEM"

If Len(Dir$(PrnDocName)) > 0 Then
SetAttr PrnDocName, vbNormal
Kill PrnDocName
End If

Many thanks
Dudley

Albert D.Kallal said:
Another minor problem is that importing your wordmerge into my database,
when I run it it opens a second copy of Access (

On a test form, place a button, and go

MergeAllWord "IncorporationQuery", _
"C:\My documents 2\access documents\word", _
True

Then open that word document by using the "modify the template" button.

Now, close the word document....note how you are prompted to save the
template..but DID NOT modify anything?

The reason why you are asked to save is that my merge code has re-set the
data source of
that word document to the text file, and NOT the mdb file.

The only reason why a 2nd copy of ms-access sis being launched is either

a) due to you writing more word code
b) using a word template that has not been created by my software

The 2nd problem above might sound confusing, but the fix is
to try the Edit the word
template using my software as I state above. My software will then setup the
word documents connection to the text file that my merge software creates
and uses. When you save the template, then the word document is now
attached to the text file..and NOT the mdb file....

So, it is actually word that is launching the 2nd copy of ms-access, not my
software. My software is designed to specially fix this problem by NOT
attached to the mdb file. Of course, my software can only make this change
to the word document if you actually open, and edit the word document using
my software menu option. "modify the template" button.
When I run 'MergeNoPrompts "mydoc",,,,"strQuery"' the computer locks up

As mentioned, try modifying the document with my software first.

Further, then try doing the merge with the menu system I built....and NOT
your code....

Get the merge working....and then..try to get the merge no prompts..and your
eventual print working.

Break this down into steps...get one thing working..and one step.at a
time...

ONLY THEN DO YOU WANT to attempt using the merge code without any prompts.

So, keep in mind, to use my word merge examples, you MUST use my interface
to create the word merge document. The key piece of information here is
that my software sets the word merge to a text file, and NEVER EVER lets the
word document attach to the actual mdb file (this is just rife with many
problems...one of which is word launching a 2nd copy of ms-access). I
explain more about this concept here....

http://www.members.shaw.ca/AlbertKallal/wordmerge/page2.html

*please* Take a Read of the above paragraph called
"Don't let word attached to you running mdb file. "

The code which works to write to file is:

Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")

I would suggest that you let my merge code complete finish...and THEN start
your code to createobject the word....and print it...

You thus *should* test this system with one line of code such as
MergeNoPrompts "MEMART", "C:\My documents 2\access documents\word", True

In fact, just reading the above line you used, the data will be based on
your form, and I think
it would be better to supply the sql to the above...

My software launches word...creates the document..and sets the focus to
the word document. At this point, do you want to allow the user to edit the
document, or do you just care to print it?

Out of a good idea, I have *just* added the ability for mergenoprmpts to
print a document, and also lets you choose what printer.

So, you can no go

dim PrnDocName as string
dim strSql as string

strSql = "select * from Incorporation where id = " & me!id

' the above will restrict the sql to the records you want. Obviously, you
can/will modify the above criteria to YOUR NEEDS.


PrnDocName = "c:\my documents 2\word
documents\electronicincorporation\memarts\DM" & _
Me![EnvelopeNumber] & ".MEM"

Can I assume that the above is the output file name you want to create as a
result of the merge?

If yes, then:

MergeNoPrompts "MEMART", _
"C:\My documents 2\access documents\word", True, _
PrnDocName, _
strSql, _
True

Note the new last option set as true. (this will have my code print the
document for you)

And, you can even set the printer to send it to, such as

MergeNoPrompts "MEMART", _
"C:\My documents 2\access documents\word", True, _
PrnDocName, _
strSql, _
True, _
"\\HCS-466\HP DeskJet 812C"

The above does not change, or touch your default printer...
(leave that pritner settng blank if you want the default printer)

I also notice that you have not given the output document a name in your
sample....

However, you can now use the above to do this...

Remember, my merge code does not NOT wait for the user.
So, if you need to print the docuemnt *AND* allow the user to
edit the resutling document, you will have to train users to print, or
create
a 2nd buttion to print the document after they done the editing of the
merged docuemnt.

However, If you just need to print the docuemnt
and save it with a name, then the above code modifications I
did will do the trick.

At least with the above new feature, you can now print..and the output
document is saved
to whatever document you want (in the above example...PrnDocName).
MergeNoPrompts "MEMART", "C:\My documents 2\access documents\word", True

Also, MergeNoPrmpts has the ability to sned the results to a docuemtn name
of your choice, perhaps you should use that feature?

Also, your code example does a word merge, deletes the word document, but
you do not give the word document a name with your code example. I have to
assume the end ensure supplies the word document name, or do you just
discard it? You also risk printing the wrong word document here, as
another document might be opened already?

I note that you do set

PrnDocName = ......

Yet, your code does not attempt to open the above prndocname with my code..
(it does however kill the document).

Do you perhaps just need to print..and NOT save the document?
(if yes..then DO NOT supply the output document for MergeNoPrompts, but set
print = true....my code will DISCARD the output document after it prints
*if* you do not supply a output document name).

And, while we are at this...for what reason do you have a SetAttr command?

Anyway, just delete the two code modules for word merge..and
re-import my new version I just posted.
example. The mergenoprompts can now print. So, the whole process should now
only take you 3 lines of code as above....

You can find it in the same old place...

http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.members.shaw.ca/AlbertKallal
 
Further to my last post, I have now found that the problem of print to file
printing garbage seems to be specific to the computer/and or printer I was
using (or something I was doing), so it should not be a problem.

Many thanks again.
Dudley

Dudley said:
Many thanks for all your help. I am very grateful that you have taken so much
trouble.

The second copy of Access problem was of course my fault. I carefully read
what you said on the subject but still did not follow your advice to paste
into your template instead of copying my own template.

Computer locking up when MergeNoPrompts...strQuery is run - I have found
that this is (if I have got it right) because when MergeNoPrompts is run on a
query it selects all records. Putting in select sql solves the problem.

I have however found a new problem with the print file. I do electronic
incorporation, and the specs require that I produce a print file in PCL5
(which is why I have to change the printer as my default is a PCL6 printer),
with the suffix .mem instead of prn. So far as I can see:

1. All print files I create through Access code print as gibberish.
2. If I open the word doc and print to file manually as DM1234.MEM it is
saved as DM1234.MEM.prn.
3. If I print manually to file as "DM1234.MEM" it saves and prints
perfectly. This is how I am doing it now (partly with a Word macro) and it
seems I will have to keep this part of my old system.

Thanks again for all your help. Opening the Memorandum and Articles document
through your wordmerge will cut down the work, and also the scope for errors
when manually finding the correct record through mailmerge.

By the way you asked why I have a SetAttr command. I put in the kill code so
that if the user finds an error and needs to re-do he can kill the old print
doc, and looking up the best way to do this I found an article on the MVP
website (co-author Doug Steele). Their code includes the SetAttr command to
normal as the kill command does not work with read only files. I could not
see how my file could be read only but I thought I might as well keep it in.

Code is
Dim strSql As String
strSql = "select * from IncorporationQuery where EnvelopeNumber = " &
Me!EnvelopeNumber
MergeNoPrompts "MEMART", , , , strSql

Dim PrnDocName As String
PrnDocName = "c:\my documents 2\word
documents\electronicincorporation\memarts\DM" & _
Me![EnvelopeNumber] & ".MEM"

If Len(Dir$(PrnDocName)) > 0 Then
SetAttr PrnDocName, vbNormal
Kill PrnDocName
End If

Many thanks
Dudley

Albert D.Kallal said:
Another minor problem is that importing your wordmerge into my database,
when I run it it opens a second copy of Access (

On a test form, place a button, and go

MergeAllWord "IncorporationQuery", _
"C:\My documents 2\access documents\word", _
True

Then open that word document by using the "modify the template" button.

Now, close the word document....note how you are prompted to save the
template..but DID NOT modify anything?

The reason why you are asked to save is that my merge code has re-set the
data source of
that word document to the text file, and NOT the mdb file.

The only reason why a 2nd copy of ms-access sis being launched is either

a) due to you writing more word code
b) using a word template that has not been created by my software

The 2nd problem above might sound confusing, but the fix is
to try the Edit the word
template using my software as I state above. My software will then setup the
word documents connection to the text file that my merge software creates
and uses. When you save the template, then the word document is now
attached to the text file..and NOT the mdb file....

So, it is actually word that is launching the 2nd copy of ms-access, not my
software. My software is designed to specially fix this problem by NOT
attached to the mdb file. Of course, my software can only make this change
to the word document if you actually open, and edit the word document using
my software menu option. "modify the template" button.
When I run 'MergeNoPrompts "mydoc",,,,"strQuery"' the computer locks up

As mentioned, try modifying the document with my software first.

Further, then try doing the merge with the menu system I built....and NOT
your code....

Get the merge working....and then..try to get the merge no prompts..and your
eventual print working.

Break this down into steps...get one thing working..and one step.at a
time...

ONLY THEN DO YOU WANT to attempt using the merge code without any prompts.

So, keep in mind, to use my word merge examples, you MUST use my interface
to create the word merge document. The key piece of information here is
that my software sets the word merge to a text file, and NEVER EVER lets the
word document attach to the actual mdb file (this is just rife with many
problems...one of which is word launching a 2nd copy of ms-access). I
explain more about this concept here....

http://www.members.shaw.ca/AlbertKallal/wordmerge/page2.html

*please* Take a Read of the above paragraph called
"Don't let word attached to you running mdb file. "

The code which works to write to file is:

Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")

I would suggest that you let my merge code complete finish...and THEN start
your code to createobject the word....and print it...

You thus *should* test this system with one line of code such as
MergeNoPrompts "MEMART", "C:\My documents 2\access documents\word", True

In fact, just reading the above line you used, the data will be based on
your form, and I think
it would be better to supply the sql to the above...

My software launches word...creates the document..and sets the focus to
the word document. At this point, do you want to allow the user to edit the
document, or do you just care to print it?

Out of a good idea, I have *just* added the ability for mergenoprmpts to
print a document, and also lets you choose what printer.

So, you can no go

dim PrnDocName as string
dim strSql as string

strSql = "select * from Incorporation where id = " & me!id

' the above will restrict the sql to the records you want. Obviously, you
can/will modify the above criteria to YOUR NEEDS.


PrnDocName = "c:\my documents 2\word
documents\electronicincorporation\memarts\DM" & _
Me![EnvelopeNumber] & ".MEM"

Can I assume that the above is the output file name you want to create as a
result of the merge?

If yes, then:

MergeNoPrompts "MEMART", _
"C:\My documents 2\access documents\word", True, _
PrnDocName, _
strSql, _
True

Note the new last option set as true. (this will have my code print the
document for you)

And, you can even set the printer to send it to, such as

MergeNoPrompts "MEMART", _
"C:\My documents 2\access documents\word", True, _
PrnDocName, _
strSql, _
True, _
"\\HCS-466\HP DeskJet 812C"

The above does not change, or touch your default printer...
(leave that pritner settng blank if you want the default printer)

I also notice that you have not given the output document a name in your
sample....

However, you can now use the above to do this...

Remember, my merge code does not NOT wait for the user.
So, if you need to print the docuemnt *AND* allow the user to
edit the resutling document, you will have to train users to print, or
create
a 2nd buttion to print the document after they done the editing of the
merged docuemnt.

However, If you just need to print the docuemnt
and save it with a name, then the above code modifications I
did will do the trick.

At least with the above new feature, you can now print..and the output
document is saved
to whatever document you want (in the above example...PrnDocName).
MergeNoPrompts "MEMART", "C:\My documents 2\access documents\word", True

Also, MergeNoPrmpts has the ability to sned the results to a docuemtn name
of your choice, perhaps you should use that feature?

Also, your code example does a word merge, deletes the word document, but
you do not give the word document a name with your code example. I have to
assume the end ensure supplies the word document name, or do you just
discard it? You also risk printing the wrong word document here, as
another document might be opened already?

I note that you do set

PrnDocName = ......

Yet, your code does not attempt to open the above prndocname with my code..
(it does however kill the document).

Do you perhaps just need to print..and NOT save the document?
(if yes..then DO NOT supply the output document for MergeNoPrompts, but set
print = true....my code will DISCARD the output document after it prints
*if* you do not supply a output document name).

And, while we are at this...for what reason do you have a SetAttr command?

Anyway, just delete the two code modules for word merge..and
re-import my new version I just posted.
example. The mergenoprompts can now print. So, the whole process should now
only take you 3 lines of code as above....

You can find it in the same old place...

http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.members.shaw.ca/AlbertKallal
 
Dudley said:
Further to my last post, I have now found that the problem of print to
file
printing garbage seems to be specific to the computer/and or printer I was
using (or something I was doing), so it should not be a problem.

Many thanks again.
Dudley

Great......

Sounds like you are jumping into the pond with this stuff!!!

My additions to the merge no prompts that lets you print without any prompts
should help also....
 
Thanks so much for your enormous help.
Dudley

Albert D.Kallal said:
Great......

Sounds like you are jumping into the pond with this stuff!!!

My additions to the merge no prompts that lets you print without any prompts
should help also....


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.members.shaw.ca/AlbertKallal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top