Solved

creating enelopes  with MSword

Posted on 2003-11-19
8
304 Views
Last Modified: 2010-05-01
hi

i have  msaccess database with list of addresses.. i want to create and print the envelopes for selected addresses from vb application .. how can i do that ? do i need to use msword for creating envelopes first and then print...?
is there  any other way.?. i wud like to  pass the dimensions of envelopes in run time if possible ..any help wud be gr8ly appreciated .. thank u
0
Comment
Question by:108a
  • 3
  • 2
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9787254
You have several options

1. Use the Access report system
2. Use the Printer object
3. Use MSWord mailmerge

The real benefits of Access report and Word mailmerge are best gained by non-programmers from within the applications. Programatically it's easier to user the Printer Object.


This shows one  way to use it

Sub PrintRoutine(rs as RecordSet)
Dim prn As Printer
Dim i As Integer
Dim j As Integer
For Each prn In Printers
If prn.DeviceName = ("MyPrinter") Then
        Exit For
    End If
Next prn

Set Printer = prn
'Printer.PaperSize = vbPRPSEnv9 'not all printers will accept any or all possible values
'Printer.PaperBin = vbPRBNEnvManual 'not all printers will accept any or all possible values
Printer.Orientation = vbPRORLandscape
Printer.Height = 1440 * 4.5 'inches to twips
Printer.Width = 1440 * 9.25
rs.MoveFirst
Do Until rs.EOF
    For i = 1 To 6
        Printer.Print vbTab & vbTab & vbTab & rs.Fields(i) & vbCrLf
    Next i
    Printer.NewPage
rs.MoveNext
Loop
Printer.EndDoc
Close rs
End Sub


Incidentally, you have 9 questions open (including this one)
0
 

Author Comment

by:108a
ID: 9793125
thanks  GrahamSkan..  iwill  try to close all the questions asap..

is  this code is for printing   Envelopes? im able to print on the plane paper ..but i  wud like to know how to print on  10X4 Inch. envelop.. thank u
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9795206
A lot depends on the printer and printer driver.

What happens now when you put envelopes in the printer?
 
Can you print these envelopes using another application, e.g. Word?

0
 

Author Comment

by:108a
ID: 9815286
hi GrahamSkan.. sorry for delay in reply...i couldn't  check your comments as i was on vacation..  im  able to print on A4 paper  ..its printing on left hand side top corner   , its not printing on envelope... im able to print it from msword .. looks like to be prob with x,y coordinates...
 thank you
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 50 total points
ID: 9816458
Yes,

You'll have to position the text by using more tabs (or spaces), or by setting CurrentX & CurrentY before printing each line.

I don't know what sort of printer you have, or how you feed in envelopes. Some have a particular bin for envelopes, others would use an adjustable bin & for others you might have to use a manual feed.

If you do have a special bin, you'll have to experiment to find out what number to call it by. The help for the printer object gives a list of constants (like vbPRBNEnvManual).

If you have an adjustable bin, you may have to set up the PaperSize, or the Height & Width properties, but you probably don't have to. It will only be necessary if the printer goes into standby displaying a message asking for the stipulated paper to be loaded.

I have just tried to an simple Inkjet printer which does not have a special bin, but does have an adjustable width. It will print on whatever paper size is loaded, even if the program asks for a different size.

So the main problem is to position the text in the right position.

This snippet positions the address more towards the centre of the envelope.

Dim prn As Printer
Dim i As Integer
Dim j As Integer
Dim LeadingSpace As String
For Each prn In Printers
If prn.DeviceName = ("EPSON Stylus COLOR 800") Then
        Exit For
    End If
Next prn
LeadingSpace = String(100, " ")
Set Printer = prn
Printer.Orientation = vbPRORLandscape ' if envelopes are end-feed
Printer.PaperSize = vbPRPSEnv10 'ignored by printer
For j = 1 To 2
    'move down 10 lines
    For i = 1 To 10
        Printer.Print ""
    Next i
   
    Printer.Print LeadingSpace & "Addressee " & j
    For i = 1 To 6
        Printer.Print LeadingSpace & "Address Line " & i
    Next i
    Printer.NewPage

Next j
Printer.EndDoc

*** Tip ***

Most of the methods for printing to the printer object and to a form are the same, so you may want use a form for testing layout, especially if you have to pay for the ink/toner and paper yourself.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

759 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

18 Experts available now in Live!

Get 1:1 Help Now