Microsoft Office Tutorials and References
In Depth Information
Mail Merge: Creating a One-to-Many List
'string field values have to be in¶
'single quotes; numeric not¶
Select Case rs.Fields(idfield).Type¶
Case adVarChar, adVarWChar 'String¶
filterString = "(" & rs.Fields(idfield) _¶
& " = '" & id & "')"¶
Case adDate¶
filterString = ""¶
Case Else 'numeric¶
filterString = "(" & idfield & " = " _¶
& id & ")"¶
End Select¶
rs.MoveFirst¶
rs.Filter = filterString¶
End Sub¶
' * * * * *¶
Function GetDataList(rs As ADODB.Recordset) As String¶
'Variable declaration¶
Dim nrCols As Long¶
Dim counter As Long¶
Dim list As String¶
nrCols = rs.Fields.Count - 1¶
'Get the table headers from the field names¶
'Skip the first field (ID)¶
For counter = 1 To nrCols¶
list = list & rs.Fields(counter).Name & sepChar¶
Next¶
'Cut off the last field separator character¶
'And append the record separator¶
list = Left(list, Len(list) - 1) & vbCr¶
'Now get the field data for each record¶
Do While Not rs.EOF¶
For counter = 1 To nrCols¶
list = list & rs.Fields(counter).Value & sepChar¶
Next¶
list = Left(list, Len(list) - 1) & vbCr¶
rs.MoveNext¶
Loop¶
GetDataList = list¶
End Function¶
' * * * * *¶
Sub CreateTable(list As String, bkm As Word.Bookmark, nrCols As Long)¶
'Variable declaration¶
Dim tbl As Word.Table¶
Dim rng As Word.Range¶
Set rng = bkm.Range¶
'Delete any old, existing table¶
If rng.Tables.Count > 0 Then¶
rng.Tables(1).Delete¶
End If¶
Wrd
Search JabSto ::




Custom Search