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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Button Question 3

Status
Not open for further replies.

CarolOB

Programmer
Sep 6, 2001
36
US
I've created a form and a report to generate invoices. I added a command button to the form which is to be used to print the invoice, however, when I click on it, I only want the invoice for the currently displayed customer to print not all the invoices in the table. Could someone please tell me what vba code to add to the event procedure that will limit the report to only print the currently displayed record? Also, does anyone know how code it so that I could have the option to either print it or e-mail it to the customer?
Any help you could offer would be greatly appreciated.
Thanks. CarolOB
 
Here's the code behind my Print command button on frmFax:

Private Sub PrintFax_Click()

Dim strDocName As String
Dim strFilter As String

strDocName = "rptFaxes"
strFilter = "FaxID = Forms!frmMainMenu!frmFaxes!FaxID"

DoCmd.OpenReport strDocName, acViewNormal, , strFilter

End Sub


I haven't used it yet but I recently came across the SendObject method. Maybe that will do what you want (e.g., email the report to your client).

Good luck!
Ann
 
I just came across this answer from Nathan:

'******begin code******
Dim email, ref, origin, destination, notes As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

'**gathers information from your form. this sets the string variable to your fields
email = Me!email
ref = Me!ref
origin = Me!origin
destination = Me!destination
notes = Me!notes

'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'***creates and sends email
With objEmail
.To = email
.Subject = ref & " " & origin & " " & destination
.Body = notes
.Send
End With

'**closes outlook
Set objEmail = Nothing
objOutlook.Quit

Exit Sub
'****end code****

Hope that helps. Have a great day!!!!
Please give helpful posts the Stars they deserve. It makes the post more visible for others

Nathan
Senior Test Lead

 
I copied and pasted the code from the e-mail portion of the reply into my code, and I changed the field names to match mine. When I click on the button to e-mail the report, I get a message: "User-defined type not defined" and it points to the lines that say:
Dim objOutlook As Outlook.Application and Dim objEmail As Outlook.MailItem.
Anyone have any ideas what is wrong with that part?
Thanks. CarolOB
 
Oh,boy. I'm not sure. Still learning this stuff myself. Do you actually have MS Outlook loaded on your PC and is it your default mail?

I put this code behind a Submit button on our MIS Work Order. It's been working fine all morning. (i.e., I'm receiving automatic email notification whenever a user submits a new work order. It's not actually sending me a database object (like the report you want to attach to an email) but maybe you use some part of this.

Private Sub Command63_Click()
Dim stDocName As String


If Me.[Frame30] = -1 And (IsNull(Me.[NLTDate]) Or IsNull(Me.[Impact])) Then
DoCmd.OpenForm "frmMsgBox--NoImpactStmt"
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Requery "ProjectNumber"
DoCmd.SendObject , , acFormatRTF, "ann@bionetics.com", , , _
"A new WO has been added", , 0

stDocName = "rptProjectStatusFromConfirmation"
DoCmd.OpenReport stDocName, acPreview, , "ProjectNumber =" & ProjectNumber
DoCmd.Close acForm, "frmProjects--DE"
End If

End Sub
 
It looks like the problem here is that the Outlook Library is not referenced in your module. Just click on tools->references. Now check Outlook 9 Object Library (or whatever your version). I think that will move things along.

-chris
 
Adding the object library solved my problem - thank you CarolOB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top