Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,376 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,614 people online right now. Registration is fast and FREE... Join Now!




Writing from User Form to MS-Word

 
Reply to this topicStart new topic

Writing from User Form to MS-Word

gram999
25 Jan, 2008 - 08:25 AM
Post #1

D.I.C Head
**

Joined: 21 Jan, 2008
Posts: 81



Thanked: 2 times
My Contributions
I am currenlty coding a user form that has three text boxes and a command button. When the form is initialized focus is set on the first textbox and the user will enter a string. In the next three textboxes the user enters an integer. When the user clicks the command button I want to write the data that was input into the text boxes to an MS-Word template or an Excel template. I have been searching the web for some guidance on how to achieve this and have found very little. Does anyone know if this is possible? If is it possible is it realitively straight forward or is it something that you really need to be an advanced VB.NET programmer to achieve? Finally, I believe that one of my problems in terms of finding some MSDN examples or guidance may be the terms that I am using to search (I have been using transferring data from user form to MS-Word, writing data from VB.NET to MS-Word, etc) If anyone can point me in the direction of what particular terms I should be searching or any type of refernce or examples that they may have seen that discusses this particualar issue I would appeciate the assistance. I would like to find something that will give me a basic idea of how to approach this and actually discusses what is going on like an MSDN article. Thanks in advance for accomodating a noob!
User is offlineProfile CardPM
+Quote Post

sharpy
RE: Writing From User Form To MS-Word
25 Jan, 2008 - 01:35 PM
Post #2

D.I.C Head
Group Icon

Joined: 2 Jun, 2007
Posts: 204



Thanked: 2 times
Dream Kudos: 275
My Contributions
QUOTE(gram999 @ 25 Jan, 2008 - 05:25 PM) *

I am currenlty coding a user form that has three text boxes and a command button. When the form is initialized focus is set on the first textbox and the user will enter a string. In the next three textboxes the user enters an integer.


Im sure that adds upto 4 textboxes.

I think you may me looking for stream writing to a .TXT or a.DOC file, look into stream reading or stream writing. There have been plenty of post within this forum covering this subject.

Example
CODE

Try
            'Write data to Temp TXT file
            Dim myWriter As StreamWriter
            Dim myStream As FileStream

            myStream = New FileStream(("c:\PCDCalc.txt"), FileMode.Create)
            myWriter = New StreamWriter(myStream)

            Dim myItem As Object
            For Each myItem In listbox1.Items
                myWriter.Write(myItem.ToString & Environment.NewLine)
            Next
            myWriter.Close()
            myStream.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error in Writing to file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try


I used this to write data from a listbox to a .txt doc in notepad. if you change .txt to .Doc then you have a word doc

Hope this helps
User is offlineProfile CardPM
+Quote Post

gram999
RE: Writing From User Form To MS-Word
25 Jan, 2008 - 08:21 PM
Post #3

D.I.C Head
**

Joined: 21 Jan, 2008
Posts: 81



Thanked: 2 times
My Contributions
Thanks for the input Sharpy. I really appreciate it. I have figured out how to get data into a formatted Excel sheet. I was hoping to be able to have the values displayed on a user form instead of a .txt file but still pondering how that would work. It would be nice then the user would not have to have MS Word or Excel installed to get a report of the inputs that they made. I was thinking of having a series of labels on a form that were activated/or created each time that user clicked a command button so it would creat a list on the user form. So it would go something like this:

(Not the actual code just psuedo code ideas I have been contemplating)

UserForm1
cmdbutton1_Click
txtbox1 = "apples" "User entered value"

UserForm2
label1 = UserForm1.textbox1

When the user clicks on the command button again Form2 would show
labe2 = UserForm1


So ultimately everytime the user clicked the command button a new label would be created on
User Form 2 that provided a sequential listing of the values that were entered into the User Form 1
txtbox thus creating a report that looked something like this:

Grocery List

1. Apples
2. Bananas
3. Grapes

Ultimately I am tying to end up with a list of the items that is updated each time
the user clicks the command button thereby creating a list/report. I know how to get the values from the textbox on Form1 to display in a label in Form2. It is just getting a list that I am having trouble with. If anyone needs to view how to get the textbox data to the label a good tutorial is here:

http://www.devcity.net/PrintArticle.aspx?ArticleID=102

I am trying to come up with the most painless solution possible. Just for reference I did find this very nice tutorial for writing to Excel if anyone is interested:

http://cislab.moorparkcollege.edu/gcampbell/advVB6-NET.htm

Thanks again for the input. It definitely gives me another option to think about.

This post has been edited by gram999: 25 Jan, 2008 - 08:31 PM
User is offlineProfile CardPM
+Quote Post

sharpy
RE: Writing From User Form To MS-Word
26 Jan, 2008 - 01:03 AM
Post #4

D.I.C Head
Group Icon

Joined: 2 Jun, 2007
Posts: 204



Thanked: 2 times
Dream Kudos: 275
My Contributions
Hi gram999

Just a quick suggestion. If you only want the data to be shown on a form, in the form of a list then try adding a listbox. You can then use this code

CODE
listbox1.Items.Add("your data here")


It may be what you are looking for

Hope this helps smile.gif



User is offlineProfile CardPM
+Quote Post

gram999
RE: Writing From User Form To MS-Word
26 Jan, 2008 - 09:57 AM
Post #5

D.I.C Head
**

Joined: 21 Jan, 2008
Posts: 81



Thanked: 2 times
My Contributions
Thanks again for all of the input Sharpy! It gives me a good arsenal to expiriment with. Have a great weekend. regards,

gram999
User is offlineProfile CardPM
+Quote Post

sharpy
RE: Writing From User Form To MS-Word
26 Jan, 2008 - 10:16 AM
Post #6

D.I.C Head
Group Icon

Joined: 2 Jun, 2007
Posts: 204



Thanked: 2 times
Dream Kudos: 275
My Contributions
No Problem

lets us Know how you get on

Cheers biggrin.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 09:13AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month