Question : Mixing Albert Kallal Mail merge with bookmark/range mail merge

I have been using Albert Kallal's mail mail (http://www.members.shaw.ca/AlbertKallal/wordmerge/index.html) successfully for quiet a while. However, it is not very useful when merging a list of conditions/items that does not have a predetermined length. For this I us a record set to merge the list as a range into a bookmark.

I can to both of these separately. What I am trying to figure out is a way to mix the two techniques together. I have been thinking that it can be done in one of two way inserting bookmarks in the template that is generated by Kallal's word merge form. Then

Either:

Modify Kallal's code to open a form that will be used to generate the sql that will be used to merge into the bookmark

or:

Let the document open and run a code when the document opens that will open an access form that will be use to generate the sql which will then merge into the bookmark in the opened document

I am hoping that some expert can advise as to which of the two is the best option and point point me in the right direction.

Cheers

SB

Answer : Mixing Albert Kallal Mail merge with bookmark/range mail merge

You mean you are only merging one main record at a time?  In that case, why do you need to use both MailMerge AND bookmarks?  I was assuming you were merging multiple "Improvement" records, and for each of these you needed to insert multiple "NonCompliance" records.

For a single record merge, you could use only bookmarks.  It appears that your code is already doing this successfully without using a mail merge at all.  Lines 22-26 are inserting fields from the parent record, and lines 29-37 are inserting the child NonCompliance records.

There is yet another approach which would work for you because the NonCompliance list is a simple list, not one that needs inserting into a table.  The trick is to use a function to assemble a delimited list of child records as a field in your query.  Then it can be treated as a single merge field.

Attached is a function named DelimitedList.

In the query that you are using for your mail merge, add the following field:

ImprovementList: DelimitedList( "Select * From NonCompliance Where [Improvement Notice ID] = " &
    [Improvement_Notice_ID], "NonCompliance", Chr(13) )

This will create a string of all the NonCompliance values matching the given [Improvement Notice ID], and separated by vbCr characters.  This can be used as a merge field and no bookmarks are required at all.

--
Graham

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Public Function DelimitedList( _
  RecordSource As String, _
  Optional ListField As Variant = 0, _
  Optional Delimiter As String = ", ") As String
Dim db As Database, rs As Recordset, sList As String
On Error GoTo ProcErr
  Set db = CurrentDb()
  Set rs = db.OpenRecordset(RecordSource, dbOpenForwardOnly)
  Do Until rs.EOF
    sList = sList & rs(ListField) & Delimiter
    rs.MoveNext
  Loop
  If Len(sList) <> 0 Then
    DelimitedList = Left(sList, Len(sList) - Len(Delimiter))
  End If
ProcEnd:
  On Error Resume Next
  rs.Close
  Exit Function
ProcErr:
  DelimitedList = "Error #" & Err
  Resume ProcEnd
End Function
Random Solutions  
 
programming4us programming4us