Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with adding buttons to form "print and email"

Status
Not open for further replies.

basictypeuser

Technical User
Jun 16, 2004
17
0
0
US
Looking for some help,

Took VB6 basic several years ago, but hoping to find some help on a word template I am creating. I want to add a print command button on the form as well a button to open my email include the specified email address, populate the subject line with some text, and attach the subject form.

I believe printing the form with some code should be fairly easy (if I could remember how)

the second button I want sounds easy but I am really lost on where to start.

Got some help already from a response ASSPIN had sent, but still need to figure out how to attach the form.

// This code will cause an e-mail to be sent
Set ol = CreateObject("Outlook.Application")
Set olns = ol.GetNamespace("MAPI")
Set olmail = ol.CreateItem(olMailItem)
With olmail
.To = "support@address.com"
.Subject = "Service Support Request"
.body = "Request form attached"
.Send
End With

Any help would be appreciated
 




Hi,

Could you not turn on the macro recorder and record printing your document. Then observe your recorded code.

Alternatively, check VBA Help for Print.

Other than that, VBA questions should be posted in Forum707.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
You might be better off posting this in the VBA forum.

However, I had a similar problem not so long ago - the mailing, not the printing.

I (not being a Word expert) ended up saving the document to the C drive of the local machine and then attaching it to the outgoing mail. You could then delete the temporarily saved document.....

'Save the completed document.
ChangeFileOpenDirectory "C:\Temp\"
ActiveDocument.SaveAs FileName:="Temp.doc", FileFormat:=wdFormatDocument

'Create the reference to Outlook
Set appOutlook = CreateObject("Outlook.Applicatio")
Set itmMail = appOutlook.CreateItem(olMailItem)

'Populate the mail and send
With itmMail
.To = "valid mail address"
.Subject = "whatever subject you want"
.HTMLBody = "anything could go here"
.Attachments.Add "C:\Temp\Temp.doc", olByValue, 1, "Your Document"
.Send
End With

'Close the mail objects
Set itmMail = Nothing
Set appOutlook = Nothing

'Close the document
ActiveDocument.Close False

....and then go on to delete the temp document.

Not sure about the printing I'm afraid......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top