Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Custom Printing from VB

Posted on 1999-01-14
8
Medium Priority
?
155 Views
Last Modified: 2010-05-03
I want to print a standard letter from VB. I want to be able to change "fields" in this letter at runtime before I print it. For example: I have a MSWord doc all nicely formatted and including some graphics, but now I want to change the name/address etc and only then print it. I'm using VB6 (VisStudio).
0
Comment
Question by:ayrezyle
[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
8 Comments
 
LVL 1

Expert Comment

by:wford
ID: 1456483
You can do this buy getting control of the word application as an object and then useing VBA to Load the file, Insert name and address into the field then tell it to print.

If this sound right I can post you some code
0
 
LVL 14

Expert Comment

by:waty
ID: 1456484
You could try the PrintPreview OCX. It will do what you need.

http://www.geocities.com/ResearchTriangle/6311/
0
 
LVL 1

Expert Comment

by:ikxsoft
ID: 1456485
try using the rich edit control to load the file, then change the field and print
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:ayrezyle
ID: 1456486
I still don't know *how* to edit those fields. I want to do some funky DTP and only then edit those fields. That implies that this RTF control must support inserted images with text over backgrounds, etc. Thus for ikxsoft's answer to be accepted, I need code that shows *how* to edit fields and how do I initialise the RTF doc. With Word I assume, but what/how/where those fields I wanna change?
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 1456487
Create bookmarks in your MSWord document. Then open this document from VB using automation. Replace the bookmarks with your values. Launch the print.

Try this code snippet:
Private Sub Command1_Click()
Dim objWord As Word.Application

    Set objWord = New Word.Application
    With objWord
        .Visible = True
        .Documents.Open "c:\test.doc"
        .ActiveDocument.Bookmarks.Item("aa").Select
        .Selection.InsertAfter "Hello"
        .PrintOut
        .Quit False
    End With
    Set objWord = Nothing
End Sub

0
 
LVL 1

Author Comment

by:ayrezyle
ID: 1456488
ummm, problem. For some reason, when I run the code above, I get the error "User-defined type not defined" with "Word.Application" highlighted <spelling?> Where/how do I get it to recognise that object type?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 1456489
In the Project References, you have to select Microsoft Word Object Library.
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 1456490
Yep, that was it! Thanks!!!
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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses

670 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