|
-
Nov 4th, 2002, 05:15 AM
#1
Thread Starter
Lively Member
Merge It with Word
Hi there.
I have a search query that uses a form field to display 1 record (searches their userID).
I then want to click a command button and merge their personal details (firstname, surname, address etc) into a word document.
I have tried different ways of achieving this (RunApp macros, VBA) but whatever I do, when Word tries to open it prompts me for the userID (as a parameter query does when you run it).
When I enter the userID, Word open with the correct data merged.
Anyone know of the best method to do this without Word prompting me for a userID.
Thanks in advance
James Brown
-
Nov 4th, 2002, 05:36 AM
#2
Lively Member
Post me the coding you use to open word.
High hopes go to all that looks down!!!
-
Nov 4th, 2002, 06:28 AM
#3
Thread Starter
Lively Member
Hi jkcontra.
Thanks, here is the code:
The select query (qu_word) UserID field filtered as below:
UserID
[forms]![frm_search_details]![UserID]
The command button code. It is placed on the frm_search_details form.
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click
Dim stAppName As String
stAppName = "WINWORD.EXE c:\TestDoc.doc [forms]![frm_search_details]![UserID]"
Call Shell(stAppName, 1)
Exit_Command22_Click:
Exit Sub
Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click
End Sub
Thanks a lot
James Brown
-
Nov 4th, 2002, 07:23 AM
#4
Junior Member
Hello,
This isn't the best way, I know, but this will work. Save the results of your query in another db...maybe access, open word and select your mailmerge fields from this new db. Then call a WordDocument.MailMerge from VB, display the new doc. (I dont know much about window handlers, but every new word window works like a stack, so the latest window is WordApplication.windows(0) )...so you can toggle visibility as reqd.
Boring solution but my twopaise! (two paise is worth a lot lot less than two pence 
Prashanth
-
Nov 4th, 2002, 07:46 AM
#5
Lively Member
I wouldnt use the Shell function. Refrence your Microsoft Word 9 OLE Object, Depends on the office you installed.
The following codes Open your document and adds the hello text.
Option Explicit
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Private Sub Command1_Click()
Set WordApp = New Word.Application
Set WordDoc = WordApp.Documents.Open(Filename)
WordApp.Visible = True
WordDoc.Select
WordApp.Selection.Text = "Hello"
End Sub
High hopes go to all that looks down!!!
-
Nov 4th, 2002, 07:55 AM
#6
Junior Member
I wasn't using a shell function to call word. My reply assumed he was using instancing the word obj. library.
Prashanth
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|