• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

Building a Word Document using VB code

I need to read a database, and take the contents of the database and build a word document with the information using VB 6. Can someone point me in the right direction on how to do this?

Thanks!
0
samic400
Asked:
samic400
1 Solution
 
cquinnCommented:
This sounds like a job for mailmerge

The best information on mailmerge I have found is here:

http://homepage.swissonline.ch/cindymeister/MergFram.htm
0
 
Shanmuga SundaramCommented:
Dim wordapp As New Word.Application
Dim cn As New ADODB.connection
Dim rs As New ADODB.Recordset

Private Sub Form_Load()
wordapp.Visible = True
wordapp.Documents.Add
cn.Open "connection string"
Set rs = New ADODB.Recordset
rs.Open "select * from tablename", cn, adOpenKeyset, adLockOptimistic
Do Until rs.EOF
wordapp.Selection.TypeText Text:="Field 1" & rs.Fields(0) & vbCrLf
wordapp.Selection.TypeText Text:="Field 2" & rs.Fields(1) & vbCrLf
wordapp.Selection.TypeText Text:="Field 3" & rs.Fields(2) & vbCrLf
wordapp.Selection.TypeText Text:="Field 4" & rs.Fields(3) & vbCrLf
rs.MoveNext
Loop
Set wordapp = Nothing

End Sub
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now