Push a button, print an envelope?

  • Thread starter Thread starter Dave Eliot
  • Start date Start date
D

Dave Eliot

I have a simple contact table and input form.

Can someone point me in the direction of finding code that will allow me
to click on a button and print a standard #10 envelope for the person
displayed on the current form?
 
I have a simple contact table and input form.

Can someone point me in the direction of finding code that will allow me
to click on a button and print a standard #10 envelope for the person
displayed on the current form?

Which part of the question is giving you difficulty?
Printing the address on the envelope or printing the correct address
for the 'person' on the form?
 
fredg said:
Which part of the question is giving you difficulty?
Printing the address on the envelope or printing the correct address
for the 'person' on the form?

Getting the name and address of the person on the form.
 
Dave Eliot said:
I have a simple contact table and input form.

Can someone point me in the direction of finding code that will allow me
to click on a button and print a standard #10 envelope for the person
displayed on the current form?

I do this all the time.

The trick here is to simply build a report that will print the envelope out.
So, simply design your report, and you usually have to place the report in
landscape mode. Most printers won't take the envelope up straight across.
Hopefully your printer has an envelope feeder. If you're planning to print
out the return address, then simply include a text label in the upper left
of the report and type in your address (that won't change for each time you
print).

For your address, simply place the fields somewhat in the center of the
report.

The next part of a little bit of trial and error, and you'll simply have to
start out usually with using full size blank sheets of paper. You jus have
to spend some time moving things around until things line up correctly...

The code behind the button to print the one record, in this case the report
is:

me.refresh
docmd.OpenReport "name of your envelope Report",,,"id = " & me!id

The above assumes that you have a primary key of "ID" in your table. If not,
just change "id" in the above to whatever you use for your primary key field
name.

Also, do try setting the page layout for an envelope. For some printers, you
may have to go into the page setup. Simply open up the report in design
mode, then go file --> page setup. You can the usually select an envelop
setting for the paper size. You can also "set" the report to a non default
printer and this works well if you have two printers, and one's always
loaded with envelopes, and thus you not have to change your default printer
to simply print out an envelope.
 
Getting the name and address of the person on the form.

First create a report that displays all of the data you want to show.

Then¡K.

Your table should have a unique prime key field.
In my example it is named [RecordID].

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview , , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

as the Where clause.

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records
 
Back
Top