Solved

Using Word Objects to save Form Data

Posted on 2002-05-20
15
123 Views
Last Modified: 2010-05-02
My form has data in the following controls:
text1
text2
combo1
combo2
combo3
picture1
Hello,
I would like to format this data into a Word Document and save it
out as a .doc file just like it is arranged on my form.  Can you
provide a piece of sample code that creates a new word document,
copies the form data to the document -- including the picture from
the picture control -- and then saves the document as a .doc file?
 Can you give advice on how to position the data in the word document
so that it matches their position on my form?


Netstallone
0
Comment
Question by:netstallone
  • 9
  • 4
  • 2
15 Comments
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi netstallone,

this is the code i put behind a commandbutton

Private Sub Command1_Click()
Dim strPicture As String
Dim oWord As Object
'Dim oWord As Word.Application
Dim oDoc As Document
 
  strPicture = "C:\temp\pic.bmp"
  'save to file
  Call SavePicture(Picture1.Picture, strPicture)
 
  'create the word object
  Set oWord = CreateObject("Word.Application")
  'Set oWord = New Word.Application
  'make it visible to see what happens
  oWord.Visible = True
  'add a new document
  Set oDoc = oWord.Documents.Add
  oDoc.Select
  'insert all the stuff
  With Selection
    .TypeText Form1.Text1.Text
    .TypeParagraph
    .TypeParagraph
    .TypeText Form1.Text2.Text
    .TypeParagraph
    .TypeParagraph
    .TypeText Form1.Combo1.Text
    .TypeParagraph
    .TypeParagraph
    .TypeText Form1.Combo2.Text
    .TypeParagraph
    .TypeParagraph
    .TypeText Form1.Combo3.Text
    .TypeParagraph
    .TypeParagraph
    .InlineShapes.AddPicture strPicture, False, True
  End With
  'delete the temp pic file
  Kill strPicture
End Sub

a sample can be picked up here (only 3K form + project file)

http://www.bredlum.com/ee_temp/vbwordsample.zip

HTH:O)Bruintje
0
 

Author Comment

by:netstallone
Comment Utility
Thanx Bruintje,
let me try this & will know u furthur.

Have a Good Day,
Netstallone.
0
 
LVL 18

Expert Comment

by:mdougan
Comment Utility
see Netstallone, someone knows this a lot better than I do ;)
0
 

Author Comment

by:netstallone
Comment Utility
Hello,Bruintje
the code u provided is showing error even in zip file its showing same error dim "o word objec" and for picture bx i want to give option for users to select their picture from thier file like opening a comdialog bx for loading pic.i'll looking forward for ur reply.Is the commanbutton for saving the project in word;cause i want to save the project as it is as i've made just like a carbon copy for e.g of yours which sended in zip format the output should come exactly like that when saved.i hope u got my point.

thankx
netstallone.
0
 
LVL 18

Accepted Solution

by:
mdougan earned 150 total points
Comment Utility
You will have to go to the Project|References menu and select the option called something like Microsoft Word Object Library 9.0 (or whatever version you have) before the code above will work.
0
 

Author Comment

by:netstallone
Comment Utility
Thanx Mr.Mdougan,
That's why i called u the best-i'll go and put the above mentioned querrie into my project.

Netstallone.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
i was really sick yesterdy so no reply,

if this works now for you then pass the points to mdougan i already saw that other thread.........

and this makes it complete

:O)Bruintje
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:netstallone
Comment Utility
mr.Bruintje
Get Well Soon,
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi netstallone, thanks for the comfort guess a lack of b... was the problem :)

did the advice from mdougan solve your problem here? in other does the little bit of code run now as you wish or do you need some more help

Take care
Brian
0
 

Author Comment

by:netstallone
Comment Utility
Hi,Mr.Brian
Well its showing dll error when i select Microsoft
Word Object Library 9.0 .i want user save them & read also so could u plz furthur explain as what coding can be done to save & read as it is as it was made.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi Netstallone,

OK first a small list of what you want to do exactly

-an VB application with some fields
-those fields have to be transferred to a Word Document
-then you want that document to be saved automatically?
-and have the document still open so the user can do some other things with it?

:O)Bruintje
0
 

Author Comment

by:netstallone
Comment Utility
Hello Mr.Briuntje,
you're almost correct i want the user to save data what they write into text-bx,combo-bx,& also picture to be saved.The way u submitted your zip sample.So when they want to send that saved file it can be done.Actually it should be saved exactly in that format as i'll create the form with txt-bx,cmb-bx,e.t.c....I hope i clarified in explaining my problem;if furthur anything u didn't get do mention me.

Bye,
Take care of ur Back.
Netstallone.
0
 

Author Comment

by:netstallone
Comment Utility
Hello Mr.Briuntje,

What happen long time no-see;i'm waiting for your codes still it's incomplete-i hope everything is fine.Plz send me the codes how to save in word format or any other way?

Netstallone.
0
 

Author Comment

by:netstallone
Comment Utility
Mr.Mike Dougan
i'm increasing the points and kindly do solve this cause i know only you can do it.

Rocky
0
 

Author Comment

by:netstallone
Comment Utility
Mr.Mike Dougan

i like to thank mike for solving my querrie & more he was very patient and understanding;wherever i'd doubts he solved all my problems.He's thorough professional & i really appreciate his efforts for being kind & supportive to amateur like me.Keep up the good work you deserve it.

Regards,
Netstallone.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now