Solved

creating enelopes  with MSword

Posted on 2003-11-19
8
307 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

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now