Solved

Using Word Objects to save Form Data

Posted on 2002-05-20
15
124 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

863 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

26 Experts available now in Live!

Get 1:1 Help Now