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

Email button on form to show report list and email selected report

Status
Not open for further replies.

trustsun

Technical User
Feb 4, 2004
73
US
Using a form, there are several reports the user can choose one and click a button to print or preview. How could this be done by emailing using the same method?

To print:
Private Sub PrintReports_Click()
Dim X As Variant
For Each X In ReportList.ItemsSelected
On Error GoTo MyErr
DoCmd.OpenReport ReportList.ItemData(X), acViewNormal
MyExit:
Exit Sub
MyErr:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume MyExit
Next
End Sub

To preview:
Private Sub ViewReports_Click()
Dim X As Variant
For Each X In ReportList.ItemsSelected
On Error GoTo MyErr
DoCmd.OpenReport ReportList.ItemData(X), acViewPreview
MyExit:
Exit Sub
MyErr:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume MyExit
Next
End Sub

The list box on the form is source like:
SELECT [msysobjects].[Name] FROM msysobjects WHERE ((([msysobjects].[Type])=-32764));
 
Hi,
To email reports, you would use the "DoCmd.SendObject" method. Here is what the code might look like (sending report, as HTML):

DoCmd.SendObject acSendReport, rptReportNameHere, acFormatHTML, "BGates@microsoft.com", , , "Report attached as HTML", strMessage, False, False

For more info on the parameters, just enter "SendObject" into the Visual Basic help system.

HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
Half way there from your suggestion but,

I would like the selection box of which format I could use like, excel, snapshot, etc. Secondly, it will be an attachment, like an outlook email box. From there I could choose any one from my email address book.

Look at my example again, I get the message "Type mismatch"
Private Sub SendReport_Click()
Dim X As Variant
For Each X In ReportList.ItemsSelected
On Error GoTo MyErr
Set X = CreateObject("Outlook.Application")
DoCmd.SendObject acReport, ReportList.ItemsSelected(X), "SnapshotFormat(*.snp)"

MyExit:
Exit Sub
MyErr:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume MyExit
Next
End Sub

thanks, alex
 
Hi,
Why are you using the variable "X" twice??? You are using to keep track of the items selected, but you are also using it to create a new instance of an Outlook object.


HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top