addressing envelope from data input form - possible?

D

Dave Eliot

I don't know where to start to try this.

I have the following fields that make up the entire address:
Fname Lname
Fname2 Lname 2
Address
City, State Zip

Is there any way to "push a button" on a form and have it print an envelope
for that record?

Thanks in advance for any help.
 
U

UpRider

Dave, put a command button on your form and have it call the below function.
You will need to substitute the names of the textboxes on your form for the
address.
vbcrlf will give you a new line, CHR$(32) is a space...
This has worked for me with Office XP, Office 2003 and Office 2007.

HTH, UpRider

'Print an envelope from the membership form
Function fcnCopyWord()
Err.Clear
Dim objWord As Word.Application
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
DoEvents
If Err.Number <> 0 Then
On Error GoTo 0
Err.Clear
DoEvents
Set objWord = CreateObject("Word.Application")
Else
objWord.Quit
DoEvents
Set objWord = CreateObject("Word.Application")
End If
objWord.Documents.Add
With objWord.Dialogs(wdDialogToolsCreateEnvelope)
'build the address lines here using your textbox names...
.addrtext = txtFIRST + Chr$(32) + txtLAST + vbCrLf + txtADDR1 +
vbCrLf + txtCITY + Chr$(32) + txtST + Chr$(32) + txtZIP
' .envreturn = " " 'This is your optional return address
.Show
End With
objWord.Quit
Set objWord = Nothing
End Function
 
J

John W. Vinson

I don't know where to start to try this.

I have the following fields that make up the entire address:
Fname Lname
Fname2 Lname 2
Address
City, State Zip

Is there any way to "push a button" on a form and have it print an envelope
for that record?

Thanks in advance for any help.

Yes; create a Report (that fits the size of the envelope you'll be printing)
with textboxes for these fields. Set the Can Grow and Can Shrink properties of
Fname2 and Lname2 textboxes to Yes (so there won't be a blank line if there is
only one name). Base the Report on a query using

=[Forms]![YourFormName]![SomeKeyField]

as the criterion, where SomeKeyField is the form control containing the field
which uniquely identifies this address.

Launch the Report from your form pushbutton. The Command Button toolbox wizard
will help you do this.

John W. Vinson [MVP]
 
D

Dave Eliot

Thanks for your help. Now I have a really dumb question. How do I call a
function for a command button? When I place a command button on the form, in
the choices listed for what action to take I don't find "calling a
function." (I'm using Access 2002 in Office XP.)

Thanks again.

Dave

UpRider said:
Dave, put a command button on your form and have it call the below
function.
You will need to substitute the names of the textboxes on your form for
the address.
vbcrlf will give you a new line, CHR$(32) is a space...
This has worked for me with Office XP, Office 2003 and Office 2007.

HTH, UpRider

'Print an envelope from the membership form
Function fcnCopyWord()
Err.Clear
Dim objWord As Word.Application
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
DoEvents
If Err.Number <> 0 Then
On Error GoTo 0
Err.Clear
DoEvents
Set objWord = CreateObject("Word.Application")
Else
objWord.Quit
DoEvents
Set objWord = CreateObject("Word.Application")
End If
objWord.Documents.Add
With objWord.Dialogs(wdDialogToolsCreateEnvelope)
'build the address lines here using your textbox names...
.addrtext = txtFIRST + Chr$(32) + txtLAST + vbCrLf + txtADDR1 +
vbCrLf + txtCITY + Chr$(32) + txtST + Chr$(32) + txtZIP
' .envreturn = " " 'This is your optional return address
.Show
End With
objWord.Quit
Set objWord = Nothing
End Function
 
R

ruralguy via AccessMonster.com

Dave,
Just use any wizard choice. Then replace the code created with:

Dim x
x = fcnCopyWord()


Since nothing is returned by the function, it can be changed to a SubRoutine
and then called with:

Call fcnCopyWord()


Dave said:
Thanks for your help. Now I have a really dumb question. How do I call a
function for a command button? When I place a command button on the form, in
the choices listed for what action to take I don't find "calling a
function." (I'm using Access 2002 in Office XP.)

Thanks again.

Dave
Dave, put a command button on your form and have it call the below
function.
[quoted text clipped - 46 lines]
 
D

Douglas J. Steele

Actually, you can use Call fcnCopyWord() even if it is a function.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


ruralguy via AccessMonster.com said:
Dave,
Just use any wizard choice. Then replace the code created with:

Dim x
x = fcnCopyWord()


Since nothing is returned by the function, it can be changed to a
SubRoutine
and then called with:

Call fcnCopyWord()


Dave said:
Thanks for your help. Now I have a really dumb question. How do I call a
function for a command button? When I place a command button on the form,
in
the choices listed for what action to take I don't find "calling a
function." (I'm using Access 2002 in Office XP.)

Thanks again.

Dave
Dave, put a command button on your form and have it call the below
function.
[quoted text clipped - 46 lines]
Thanks in advance for any help.

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
D

Dave Eliot

This was great help. Finally got around to it today -- and it works just
fine!

Thanks again.

Dave

John W. Vinson said:
I don't know where to start to try this.

I have the following fields that make up the entire address:
Fname Lname
Fname2 Lname 2
Address
City, State Zip

Is there any way to "push a button" on a form and have it print an
envelope
for that record?

Thanks in advance for any help.

Yes; create a Report (that fits the size of the envelope you'll be
printing)
with textboxes for these fields. Set the Can Grow and Can Shrink
properties of
Fname2 and Lname2 textboxes to Yes (so there won't be a blank line if
there is
only one name). Base the Report on a query using

=[Forms]![YourFormName]![SomeKeyField]

as the criterion, where SomeKeyField is the form control containing the
field
which uniquely identifies this address.

Launch the Report from your form pushbutton. The Command Button toolbox
wizard
will help you do this.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top