smejicoiii
IS-IT--Management
Hi all first time here and I am trying to automate a merge document with input from the user. Debugging everything seems to be working fine until it gets time to finish and merge the document, any help would greatly be appreciated.
Code is below...
Sub testmerge()
'
' testmerge Macro
'
'
ActiveDocument.MailMerge.OpenDataSource Name:= _
"H:\worddata\Setup\database.mdb SetupFile.odc", ConfirmConversions:= _
False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=MSDASQL.1;Persist Security Info=True;Extended Properties=""DSN=CaseList;DBQ=\\10.0.0.10\database.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"";Initial Catalog=\\10.0.0.10\database.mdb" _
, SQLStatement:="SELECT * FROM `SetupFile`", SQLStatement1:="", SubType:= _
wdMergeSubTypeOther
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
Dim dsMain As MailMergeDataSource
Dim numRecord As Integer
Dim strReference As String
strReference = InputBox("Enter Client Reference")
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
Set dsMain = ActiveDocument.MailMerge.DataSource
If dsMain.FindRecord(FindText:=strReference, _
Field:="File_no") = True Then
numRecord = dsMain.ActiveRecord
End If
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With dsMain
.FirstRecord = numRecord
.LastRecord = numRecord
End With
.Execute Pause:=False
End With
End Sub
Code is below...
Sub testmerge()
'
' testmerge Macro
'
'
ActiveDocument.MailMerge.OpenDataSource Name:= _
"H:\worddata\Setup\database.mdb SetupFile.odc", ConfirmConversions:= _
False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=MSDASQL.1;Persist Security Info=True;Extended Properties=""DSN=CaseList;DBQ=\\10.0.0.10\database.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"";Initial Catalog=\\10.0.0.10\database.mdb" _
, SQLStatement:="SELECT * FROM `SetupFile`", SQLStatement1:="", SubType:= _
wdMergeSubTypeOther
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
Dim dsMain As MailMergeDataSource
Dim numRecord As Integer
Dim strReference As String
strReference = InputBox("Enter Client Reference")
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
Set dsMain = ActiveDocument.MailMerge.DataSource
If dsMain.FindRecord(FindText:=strReference, _
Field:="File_no") = True Then
numRecord = dsMain.ActiveRecord
End If
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With dsMain
.FirstRecord = numRecord
.LastRecord = numRecord
End With
.Execute Pause:=False
End With
End Sub