The life of era - a vb6 program

11
The life of era Visual Basic 6.0 Create a data from Visual Basic and print an output to MS Word. Written and Designed by Mark John P. Lado No part of this book may reproduce without written consent from the author. By using this book you agree not to use this for any purpose that is illegal. You agree not to alter, modify, or cause the alteration or modification, of the book, without prior written consent from the author.

Transcript of The life of era - a vb6 program

Page 1: The life of era - a vb6 program

The life of era

Visual Basic 6.0

Create a data from Visual Basic and print an output to MS Word.

Written and Designed by

Mark John P. Lado

No part of this book may reproduce without written consent from the author. By using this

book you agree not to use this for any purpose that is illegal. You agree not to alter, modify,

or cause the alteration or modification, of the book, without prior written consent from the

author.

Page 2: The life of era - a vb6 program

ACKNOWLEDGEMENT First and foremost to our Almighty God for giving me strength every day for the guidance and good health, for the graces and blessings that help me in making the project possible. And most of all to my parents and guardians, thank you for showing your unconditional love and unending support financially and spiritually.

Page 3: The life of era - a vb6 program

INTRODUCTION

The book contains programming codes which is written in VB6 or the Visual Basic 6. In this book, you will learn on how to create a simple program, print a data from visual basic

to Microsoft Word and other basic procedures. This is a beta version only where the reader

can get some ideas in performing the project. This Book contains screen shots of the actual

program and their respective source code.

Page 4: The life of era - a vb6 program

INTERFACE AND SOURCE CODE

Page 5: The life of era - a vb6 program

Show Form

To show another form from the current form you need to use command button and add it

to your current form.

And create another form where when you click the command button the next form will

show up.

Then double click the command button then write the codes and then run.

Private Sub Command1_Click()

Form1.Hide

Form2.Show

End Sub

Page 6: The life of era - a vb6 program

Print data using ms word.

In this section you need to add labels, text boxes and one command button for print.

Rename it.

Page 7: The life of era - a vb6 program

The label1 is for name, label2 is for age, label3 is for address. The textboxes is the same as

label but not the same function. Just remove the text of textboxes. Change also the caption

of command button into Print.

After making the interface, open an empty Microsoft word and create your template so that

when you click the print button from your vb6 you will be directed to ms word.

Page 8: The life of era - a vb6 program

In your word, go to developer’s ribbon. And add text form, same format as you did in your

vb6 program.

Page 9: The life of era - a vb6 program

As you see there is and dark boxes. Right click on it and go to properties. In the bookmark

rename the default text1 into w_name, do this to the age and address. And after editing

save it as template and put it where your visual basic program located.

Page 10: The life of era - a vb6 program

Go back to your program.

Double click the print button and write the codes. Observe properly.

Private Sub Command1_Click()

Static wd1 As Word.Application

Static wd1Doc As Word.Document

Set wd1 = New Word.Application

wd1.Visible = True

Set wd1Doc = wd1.Documents.Add(App.Path & "\mytemplate.dot")

With wd1Doc

.FormFields("w_name").Range = Text1.Text

.FormFields("w_age").Range = Text2.Text

.FormFields("w_address").Range = Text3.Text

End With

Set wd1 = Nothing

Set wd1Doc = Nothing

End Sub

Page 11: The life of era - a vb6 program

Setting references

Set ms word references so that you can connect. Find the Microsoft Word 12 Object Library

and check. And save your project where your template was.

Test your program.