I have a field in a database, ending with :. My idea was to use { INCLUDEPICTURE "pathname{MERGEFIELD f1}.jpg", having stored previously the images' names in a folder with the names of the field values. However, I cannot name a file with a : character in it, and I thought of using the replace function inside the query that is inside the OpenDatasource function in ms word, but it does not work apparently.
Here goes the code:
Private Sub Document_Open()
Dim strConnection As String
With Me.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource _
Name:="E:\jobDB.mdb", _
LinkToSource:=True, AddToRecentFiles:=False, ConfirmConversions:=True, _
Connection:="TABLE t1", SQLStatement:="SELECT t1.name, replace(t1.f1, """:""", """") as repFld FROM t1;"
End With
End Sub
Private Sub Document_Close()
If Me.MailMerge.State = wdMainAndDataSource Then _
Me.MailMerge.MainDocumentType = wdNotAMergeDocument
End Sub
Doing so, I was hoping to remove the : and make INCLUDETEXT work, but this does not work and when the code is executed, a dialog box is shown for me to select the table of the database.
I don't know if theres is something wrong, or if there is another way of achieving this, or if there is any field or tag or flag to replace characters inside a mergefield.
I wanted to use VBA only for connecting to the datasource andbut I wanted to use mailmerge for this since I researched how it works and I could do what i wanted with conditional fields, otherwise I will have to use VBA and formfields.