Hi guys,
I need to put the results of a query to an acces database onto a word document. now the query is driven by user choices so it might return one record or it might return over 300 records or then again, nothing at all. but if there is at least one record returned, this is needed to be desplayed on a word document that is going to have to be designed on the fly in code. since I am new to programming (not a student, working!!) i would like some help on this please. i have got as far as getting the info out of the database, just need help on putting it into a word document.

Hi guys,
I need to put the results of a query to an acces database onto a word document. now the query is driven by user choices so it might return one record or it might return over 300 records or then again, nothing at all. but if there is at least one record returned, this is needed to be desplayed on a word document that is going to have to be designed on the fly in code. since I am new to programming (not a student, working!!) i would like some help on this please. i have got as far as getting the info out of the database, just need help on putting it into a word document.

I've a code that acts like the similar way u want.Try this code.I think it will give u an idea how to do word writing from vb programs.If u still have problems then mail me.My email id is :
choudhuryshouvik@yahoo.com

Insert the following references into your project before trying to run this code :
Microsoft Word <version no> Object Library
from Project->References

Here is the code:-
'add a textbox(text1).also add two command buttons and name 'them cmdclose & cmdword respectively.

Option Explicit
Dim wrdapp As Word.Application

Private Sub cmdclose_Click()
On Error GoTo cerror

wrdapp.ActiveDocument.Close
wrdapp.Quit

cerror:
If Err.Number = 4198 Then
Dim ex As Integer
ex = MsgBox("Do you want to save this file or quit ?", vbYesNo + vbQuestion, "Microsoft Word with VB")
If ex = vbNo Then
'Close the current document
wrdapp.ActiveDocument.Close
'Close Word
wrdapp.Quit
ElseIf ex = vbYes Then
Exit Sub
End If
'Exit Sub
End If
End Sub

Private Sub cmdword_Click()
Set wrdapp = New Word.Application
With wrdapp
'Show Word
.Visible = True
'Create New Document
.Documents.Add
'Add text to the document
.ActiveDocument.Content.Text = "Hi, " & Trim(Text1.Text)
End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set wrdapp = Nothing
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.