Mail Merge

  • Thread starter Thread starter simon7115
  • Start date Start date
S

simon7115

Guest
hi, i am doing a project in ACCESS for my A-Level computing project and was wondering can anyone help. i am trying to create a button which will run a mail merge so the end user can press the button to mail merge as they dont really know much about using computers? there is a way to do it as someone in my class has found it but he wont tell anyone.

would be so greatful

many thanks

simon Evans (simeopee@yahoo.com)
 
There are a number of options:

1. Don't mailmerge, use a report as it does basically the same thing.
2. Hyperlink to the word document, the user would still have to press the mailmerge document.

3. Use automation to manage the opening of the work document as in:

Code:
Public Function CreateLetters()
' Open a letter in Word and insert text - used by menu command.
'You must put Word in the DAO Reference Library.
    Dim Dbs As Database, rstTEMPOwnersMerge As Recordset
    Dim appWord As Word.Application
    Dim intPages As Integer, StrMessage, I As String
    Dim rstSourceTable As String
    Dim Worddoc As String
    Dim Resp As Integer
    Dim Resp2 As Integer
    
    'Make declarations of Source and MergeFiles
    rstSourceTable = "TempOwnersMerge"
    Worddoc = "C:\AAA My Documents\AISolutions\Products\Y2K9 Conrol\Y2K9 Product\Letters\dog warden questionnaire - stray.dot"
    
    Resp = MsgBox("This procedure can take up considerable system resources." & Chr(13) & _
    "To ensure adequate resources are available close down all non-essential programs" & _
    " including Word." & Chr(13) & _
    "Do you want to cancel this procedure to close some programs?", vbYesNo, "READ ME")
    ' Open a recordset based on the Merge query.
    If Resp = vbYes Then
    Exit Function
    Else
    
    
    'Run the Query to Create the Temporary Table
    DoCmd.SetWarnings False
    DoCmd.OpenQuery ("MergewithChargedOwners"), acViewNormal, acReadOnly
    DoCmd.SetWarnings True
    Set Dbs = CurrentDb()
    Set rstTEMPOwnersMerge = Dbs.OpenRecordset(rstSourceTable)
    
    
    ' If no one has open issues, display a message and exit.
    If rstTEMPOwnersMerge.RecordCount = 0 Then
        MsgBox "There are no matching records for your criteria, please try again", 0, "No Records"
        Exit Function
    End If

    'Switch to Microsoft Word so it won't go away when you finish.
    On Error Resume Next
    AppActivate "Microsoft Word"
    
    'If Word isn't running, start and activate it
    If Err Then
    Shell "c:\Program Files\Microsoft Office\Office\" _
        & "Winword /Automation", vbMaximizedFocus
    AppActivate "Microsoft Word"
    End If
    On Error GoTo 0
    
    'Get an Application object so you can automate Word.
    Set appWord = GetObject(, "Word.Application")
    
    'Open a document based on the memo template, turn off the
    'spell check
    
    With appWord
        .Documents.Add Worddoc
        .ActiveDocument.ShowSpellingErrors = False
    End With
    
    MsgBox "The letter is now on screen and is ready for final editing and merging", 0, "Letter Ready..."
    
    
    End If

Set Dbs = Nothing
Set rstTEMPOwnersMerge = Nothing
Set appWord = Nothing

Set StrMessage = Nothing
End Function
 
Continuing...

You must have set the word document up as a mail merge to the specific datasource before trying to run this code.
 
Just trying to have a go with this and i have a couple of questions if someone could answer. There seems to be listed a qry and a table within the code.

Can i assume that the query is a standard one?


There is mentioned:

MergeWithChargesOwners (This is the standard query????)

rstSourceTable (Is this a pre defined table already in the database?)

rstTempOwnersMerge (Is this table created by the code??)

I was trying to run this from just a simple query but it seems to use slightly more than that. I was under the impression that it will run the query automatically, create a temporary table to store the info in and then run the word mail merge.

The second problem would then be, assuming i am not being an idiot and it does actually create a temp table, where would i point the mail merge to from word? I would have originally pointed it to the query.

Any help would be greatly appreciated!!!

Thanks
 
if someone please can help

I have used the obove code the only problem i have is that i can't open word application, it highlts -----> Set appWord = GetObject(, "Word.Application"), can someone help. Everything else is working.
 

Users who are viewing this thread

Back
Top Bottom