Solved

Using Word Objects to save Form Data

Posted on 2002-05-20
15
126 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
ID: 7021134
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
ID: 7021175
Thanx Bruintje,
let me try this & will know u furthur.

Have a Good Day,
Netstallone.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7021434
see Netstallone, someone knows this a lot better than I do ;)
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:netstallone
ID: 7023316
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
ID: 7023811
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
ID: 7024335
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
ID: 7026234
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
 

Author Comment

by:netstallone
ID: 7026425
mr.Bruintje
Get Well Soon,
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7027706
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
ID: 7028878
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
ID: 7029046
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
ID: 7029641
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
ID: 7041550
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
ID: 7083813
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
ID: 7100004
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

830 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