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