Hi,
I have MS Access tool used for mail merge. Mail Merge is done using different letter templates e.g all records in the DB with Code A1 go to a letter template A1, Code A2 records are mail merged to template A2 etc.
To perform the mail merge I have created as many queries in Access as there are letter codes and there lies the problem. All the queries are identical except for the name and the filter criteria which is the letter code e.g A1 or A2
Is it possible to have one query that I can pass the letter code via vba ?
Below is the piece of code that calls the 10 queries
Appreciate all ideas in advance
Thank you
Chris
I have MS Access tool used for mail merge. Mail Merge is done using different letter templates e.g all records in the DB with Code A1 go to a letter template A1, Code A2 records are mail merged to template A2 etc.
To perform the mail merge I have created as many queries in Access as there are letter codes and there lies the problem. All the queries are identical except for the name and the filter criteria which is the letter code e.g A1 or A2
Is it possible to have one query that I can pass the letter code via vba ?
Below is the piece of code that calls the 10 queries
Private Sub Command0_Click()
/*some lines of code has been left out*/
Generate_letter "A1", "A1"
Generate_letter "A2", "A2"
Generate_letter "A3", "A3"
Generate_letter "A4", "A4"
Generate_letter "A5", "A5"
Generate_letter "A6", "A6"
Generate_letter "A7", "A7"
Generate_letter "A8", "A8"
End Sub
Public Function Generate_letter(fCriteria As String, XXX As String)
/*some lines of code has been left out*/
With oMainDoc.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = AssignDbPath
.OpenDataSource Name:=sDBPath, _
ConfirmConversions:=False, _
ReadOnly:=False, _
LinkToSource:=True, _
AddToRecentFiles:=False, _
Revert:=False, _
Format:=wdOpenFormatRTF, _
Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0; " & _
"User ID=Admin;" & _
"Password='';" & _
"Data Source=" & sDBPath & ";" & _
"Mode=Read;", _
SQLStatement:="SELECT * FROM `" & fCriteria & "`", SQLStatement1:="", _
Subtype:=wdMergeSubTypeAccess
End With
/*some lines of code has been left out*/
End Function
Appreciate all ideas in advance
Thank you
Chris