wordmerge works in .mdb but not .mde?

Happy YN

Registered User.
Local time
Today, 10:46
Joined
Jan 27, 2002
Messages
425
I have read much code about mailmerging but I came across a simple bit of code in one of MS sample files which opens a wizard asking user whether he wishes to merge to new doc or existing etc and it works beautifully.

However I have two seemingly easy obstacles.
1. when I open from the mde version of the same file it opens word and when it tries to link to the db it says that its currently locked by another user etc.??
2. In desigm mnode everything was fine but in run mode , all of a sudden the main db window (the one showing all tables queries reoprts etc) opened up, something I would never want a user to see , never mind have access to!

Here is my code:
Private Sub cmdMerge_Click()
Dim strQry As String
If Me.lstReports.Value = 14 Then
strQry = "qryparentslabels"
ElseIf Me.lstReports.Value = 15 Then
strQry = "quickprint"
End If
DoCmd.SelectObject acQuery, strQry, True
DoCmd.RunCommand acCmdWordMailMerge

End Sub

Thanks
 
OK I have found the code to hide the db window
DoCmd.RunCommand acCmdWindowHide
but what about my main problem?
thanks
 
I'm having this same problem - my mailmerge automation function works pefectly when my database is an MDB but after converting it to an MDE file it seems want to do the connection as ODBC rather than DDE. Is there any way I can force the data to be passed via DDE programmatically? My code is as follows:

Code:
Public Sub MergeIt(strDatatoMerge, strMergeTemplate, strEnterMergedDocFileName, strDocType As String)
Dim wordApp As Object 'using late binding to avoid bug which causes Access to crash when using .ActiveWindow.Selection.Find method
Dim MergeDoc As Word.Document
Dim strMergedDocFileName As String
Dim strConnection As String
Dim ProgressMeter As Integer
Dim strDatabaseName As String

On Error GoTo Err_MergeIt
    DoCmd.Hourglass True

    Set wordApp = CreateObject("Word.Application")

    With wordApp
        Set MergeDoc = .Documents.Open(strMergeTemplate, , ReadOnly)
        strMergedDocFileName = strEnterMergedDocFileName
        strConnection = "QUERY " & strDatatoMerge
            With MergeDoc
                .MailMerge.OpenDataSource Name:=CurrentDb.Name, Connection:=strConnection, SubType:=wdMergeSubTypeWord2000

                .MailMerge.Destination = wdSendToNewDocument ' Execute the mail merge and close the merge document.
                .MailMerge.Execute
                .ActiveWindow.Close savechanges:=wdDoNotSaveChanges
            End With
        
    DoCmd.Hourglass False

If DoesFileExist(strMergedDocFileName) = False Then 'Check to see if a file with the path in strMergedDocFilename already exists; if not, save the file, if yes, prompt user about overwrite
                .ActiveDocument.SaveAs Filename:=strMergedDocFileName
            ElseIf MsgBox("An order with this filename already exists. Do you want to overwrite it?", vbExclamation + vbYesNo, "File already exists") = vbYes Then
                .ActiveDocument.SaveAs Filename:=strMergedDocFileName
            End If
        .Visible = True
 
With the code above,

Code:
.MailMerge.OpenDataSource Name:=CurrentDb.Name, Connection:=strConnection, SubType:=wdMergeSubTypeWord2000

it is trying to connect the wordmerge document to the current database which, in your case, is the .mde file.

I had that problem at one time and the only way to fix it (that I know of) is to split your database into a frontend and backend and then;

Change the code above to point to the backend
OR
Remove that line of code, and change your actual merge template to include a static connection to your backend
 
is your document you are going to merge to open? you cannot mailmerge if the document file is open.
 

Users who are viewing this thread

Back
Top Bottom