Results 1 to 6 of 6

Thread: Merge It with Word

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Leeds
    Posts
    72

    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

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Location
    South Africa
    Posts
    88
    Post me the coding you use to open word.
    High hopes go to all that looks down!!!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Leeds
    Posts
    72
    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

  4. #4
    Junior Member prashx's Avatar
    Join Date
    Jul 2002
    Location
    chEnnai
    Posts
    30
    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

  5. #5
    Lively Member
    Join Date
    Sep 2002
    Location
    South Africa
    Posts
    88
    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!!!

  6. #6
    Junior Member prashx's Avatar
    Join Date
    Jul 2002
    Location
    chEnnai
    Posts
    30
    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
  •  



Click Here to Expand Forum to Full Width