Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Word Objects to save Form Data

Posted on 2002-05-20
15
Medium Priority
?
133 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 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