| | |
Automate Microsoft Word From VB6
![]() |
•
•
Join Date: May 2007
Posts: 1
Reputation:
Solved Threads: 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 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
![]() |
Similar Threads
- Microsoft Word: Can't change margin (Windows Software)
- Microsoft Word abnormal termination (Windows Software)
- Microsoft Word Dictionary Problem (Windows Software)
- Microsoft Word Spelling Dll (Windows NT / 2000 / XP)
- Where did my Microsoft Word Clip Art go? (Windows Software)
- Microsoft word starting up in OS 9 (Mac Software)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How to check MP3 disc
- Next Thread: About Progress Bar
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





