Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I put selected contacts (from Forms) to a WordDocument??

Status
Not open for further replies.

liwan

Technical User
Aug 10, 2003
22
AU
Dear Ppl,
I am not good in programming. I have a database full of company's contacts. In my database,I have a from that shows particular contact person when the project no is entered. The form show the list of contact, at the same time able to be selected and place in another lisBOx. How do I place the selected contacts into a word template which open as document(this part is reasy). I just wanted to know how put contacts into the word document.
P/S: Urgently needed,please please please help!

Regards,
liwan

 
Hi, I had problems with trying to set up mail merge before, and to work around it I used update queries. Ok, in my database, which holds Nurses details, the users can view a Nurses Details, and on that form there is a Button called "Send Letter". All this was required to do was Open MS Word, with their name and address filled in, ready for a letter to be typed in. Easy, I think not.

To do this, the form name, "NurseDetails" is used in the update query criteria, to create a new temp table called "tempNurseDetails". This table would simply hold that Nurses details and nothing else. So... The Update query code....

SELECT Nurses.[Nurse ID],Nurses.Title, Nurses.[Full Name], Nurses.[Home Address], Nurses.[Correspondance Address] INTO [tempNurseDetails]
FROM Nurses
WHERE (((Nurses.[Nurse ID])=[Forms]![NurseDetails]![NurseID]));

Now, what this code does is puts the current record into a table called "tempNurseDetails", overwriting any information int hat table, and creating it if not present.

Now, go forth and make the Merge Document from this table - select the table, and go to Tools > Office Links > Merge it With Word. Everything should work perfectly!

One problem which was facing me was that MS Access, when using a mail merge, opens another instance of access, so it can't read the user selected details from the other open Database, this is why the Update query worked best for me.

I'm not sure if this example would be much use to you, but if you post some more details about the problem, I'm sure I could help!

David
 
Dear DawsonUK,

I understand partial of your suggestion but my form is already base on a query that select the few fields I wanted and I also have a button that open the Word Document(which is a ready template in J:\ drive)The word document is all ready template to be open as word.doc
So, do I start over again with another query? Merging it would not be the template I wanted. Do you wanna see code of the open template or SQL of query?thanks for your time

regards,
liwan
 
Hi, what you should do it in your query it will be in the format of something like this....

Select table.field, table.field2 etc etc
From table

Now, after your select statement add this....
INTO temp-contactsTable

so it'll look like this....
Select table.field, table.field2 etc etc
INTO temp-contactsTable
From table

Now, on your form, use this code....
'Turn off warnings
DoCmd.SetWarnings False
'Run Query
DoCmd.OpenQuery "Mail Query Name"
'Turn on warnings again
DoCmd.SetWarnings True

'Open Word Document
Dim docname As String
docname = "C:\Program Files\PostRegDatabase\Docs\Mergedot"
Dim objApp As Object
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open docname

What this code does, is runs the query, which puts all your query results into a table (without any annoying confirm messages). The second part opens the merge document. This document should be setup from Word using a mail merge, selecting the temp-contactsTable as the data source.

I hope this helps you understand my inital post a bit better. Feel free to email me if you need help.

David
Email : d.dawson@rgu.ac.uk

 
I find the easiest way to merge data into a Word template is to use bookmarks. If data is to be merged from several tables/fields to several locations in the doc, you can use the fieldname as the bookmark text:

[Tablename.Fieldname]

Then it's easy to iterate the Bookmarks collection and replace the bookmark text with data:

objDoc.Bookmarks(n).Range.Text = strNewData

Paul Bent
Northwind IT Systems
 
Dear PaulBent,

I couldn't seems to find any bookmarks that you mention for this case. I click on the help index just some example but there isn't a function like that.Please let me know where I can find it.

Thanx,
Liwan
 
Dear Dawson,
I tried to build a query like you said. But this query doesn't seems rite. THere's error on this query. These are the SQL.

SELECT Project.[Proj No], Project.[Comp Name], Contacts.[Cont Name], [Company Test].[Comp Fax]
FROM Project, [Company Test] INNER JOIN Contacts ON [Company Test].[Comp ID] = Contacts.[Comp ID]
ORDER BY Project.[Proj No]
INTO tblList;

I selected field from table. So I can't continue from there. And where do I put the DoCmd.SetWarning codes? In the template or in the form that contain the selected contacts.Here is the original query I put in the form which list out the field I wanted.Then I will click on the list to select. How do I get the selected ones in to the template which have particular space to input the selected contacts.
SELECT DISTINCTROW Project.[Proj No], Project.[Comp Name], Contacts.[Cont Name], [Company Test].[Comp Fax]
FROM [Company Test] INNER JOIN (Contacts INNER JOIN Project ON Contacts.[Comp Name] = Project.[Comp Name]) ON [Company Test].[Comp Name] = Contacts.[Comp Name]
GROUP BY Project.[Proj No], Project.[Comp Name], Contacts.[Cont Name], [Company Test].[Comp Fax]
HAVING (((Project.[Proj No])=[Forms]![ProjectContacts]![Combo3]));
Thanks in advance!!

Regards,
Liwan
 
Dear Paul,

Thanks for the reply but bookmark is not the thing Iam looking for!Bookmark is just putting in words into document.Where as I wanted VB coding to get the selected contact from the form.That is the main part.Getting it from the form and putting it in to a document which is a template from a particular drive.
Hope you can help!
Thanks,
Liwan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top