Solved

Using Word Objects to save Form Data

Posted on 2002-05-20
15
125 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 54
message box in access 4 46
Set email body to html using vbscript 6 41
VBA: copy range dynamically based on config sheet v2 3 33
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

773 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