-1

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.

2
Contributors
1
Reply
4
Views
10 Years
Discussion Span
Last Post by choudhuryshouvi
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.