PDA

Click to See Complete Forum and Search --> : exporting to word?


oriole72
Mar 22nd, 2000, 02:23 AM
I have a database that holds personal information such as First Name, Last Name, Address, Postal Code, etc...and I was wondering if there was a way to export this information into a word document. Say in my visual basic program the user is viewing a record, and then wants to write them a letter...how can i export this information into word, as mentioned before.....any tips, ideas, or how-tos would be greatly appreciated.

zambian
Mar 22nd, 2000, 02:55 AM
U'll need 2 declare a word object and get the field values either from the form or the database(using a query) and use the code below to save it in doc (or rtf, or html or ascii text ) format.

Dim w As New Word.Application ' instance of MsWord

Dim strData as String

...' Query to retrieve values from the Database
...' or expressions to retrieve values from forms
...' Store these values in strData


w.Documents.Add ' Add a new document to word session
w.Selection.TypeText (strMsg)
w.ChangeFileOpenDirectory (App.Path)

w.ActiveDocument.SaveAs FileName:="test" & ".doc", _
FileFormat:=wdFormatDocument, LockComments:=False, _ Password:="", _
AddToRecentFiles:=True, WritePassword:="", _
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False

w.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
w.Application.Quit
Set w = Nothing
...
...
..

This will save the value in strData in a word file (.doc) in the directory App.path with filename Test.doc

If U want a sample prg, let me know and I'll mail it to you.

The SaveAs portion of this code is got by going to MsWord and clicking Tools->Macro->Record New Macro and give macro name.
Then type any text in the doc. U then click file,->Save As
and then give a filename an hit Ok.

Then Tools->Macro->Stop Recording.

And finally Tools->Macro->Macros and Click Edit after selecting the macro u saved.

Just cut and paste the code generated.

To save it as another type(html, rtf, etc) select that type in when saving the doc.

If u want more info on manipulating word , let me know....

Hemang

danny2u
Oct 19th, 2005, 02:02 AM
hi zambian,

my situation is that i use vb6 and active report as my report function. the only thing trouble me is that whenever i export to *.rtf and then the box gone also microsoft word cannot identify as header and footer it.

can u help me?
thank you.