VB Code for Emailing and Sending Report to File

rocel

New member
Local time
Tomorrow, 04:23
Joined
Jun 8, 2010
Messages
1
Hi guys,
I'm a newbee here. Am also newbee in access. I have started a database for our company assets using Access. So far things are going right on track when suddenly i'm faced up with a problem in determining the right VB code.
In my Menu I have 4 buttons: one for viewing a report, one for printing a report, then one for emailing a report, and finally sending a report to file. I was able to successfully perform the viewing and printing a report. When i decided to add the emailing and sending a report, I got lost. I dont know anymore how to go about it. Can anybody help me? I just need to know how to go about emailing and sending a report. Here is my code:

Option Compare Database ' Use database order for string comparisons.
Option Explicit ' Requires variables to be declared before they are used.

Sub PrintReports(PrintMode As Integer)
On Error GoTo Err_CommandPrevReport_Click
' This procedure used in Preview_Click and Print_Click Sub procedures.
' Preview or print report selected in the ReportToPrint option group.
' Then close the Print Sales Reports Dialog form.

Dim strWhereCategory As String
strWhereCategory = "Plnt_Name = Forms![Plant Data Option Print Form]!PlantListBox1"
Select Case Me!ReportToPrint1
Case 1
'DoCmd.OpenReport "SL Summary Report", PrintMode

If IsNull(Forms![Plant Data Option Print Form]!PlantListBox1) Then
DoCmd.OpenReport "SL Summary Report", PrintMode
Else
DoCmd.OpenReport "SL Summary Report", PrintMode, , strWhereCategory
End If

Case 2

If IsNull(Forms![Plant Data Option Print Form]!PlantListBox1) Then
DoCmd.OpenReport "Fixed Assets Per Plant Report", PrintMode
Else
DoCmd.OpenReport "Fixed Assets Per Plant Report", PrintMode, , strWhereCategory
End If
End Select

Exit_CommandPrevReport_Click:
Exit Sub
Err_CommandPrevReport_Click:
Resume Exit_CommandPrevReport_Click
End Sub

Private Sub CommandClose_Click()
' This code created by Command Button Wizard.
On Error GoTo Err_CommandClose_Click
Dim stDocName As String
Dim stLinkCriteria As String

' Close form.
DoCmd.Close
stDocName = "Main Menu"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_CommandClose_Click:
Exit Sub

Err_CommandClose_Click:
MsgBox Err.DESCRIPTION
Resume Exit_CommandClose_Click
End Sub

Private Sub CommandPrevReport_Click()
' Preview selected report. This procedure uses the PrintReports
' Sub procedure defined in (General) section of this module.

PrintReports acPreview

End Sub

Private Sub CommandPrintReport_Click()
' Print selected report. This procedure uses the PrintReports
' Sub procedure defined in (General) section of this module.
PrintReports acNormal

End Sub

Private Sub ReportToPrint1_AfterUpdate()
' Enable SelectCategory combo box if user selected Sales by Category
' report.
Const conPlantData = 2
If Me!ReportToPrint1.Value = conPlantData Then
Me!PlantListBox1.Enabled = True
Else
Me!PlantListBox1.Enabled = True
End If

End Sub

Private Sub PlantData_GotFocus()
End Sub

Private Sub PlantListBox1_BeforeUpdate(Cancel As Integer)
End Sub
 
How about a new Macro to output to a snap file or rtf?
 

Attachments

  • Clipboard01.jpg
    Clipboard01.jpg
    92.9 KB · Views: 233
Hi Rocel,

Are you in the US or the UK ?

Daft question but we are about to release a new Company asset, Company Vehicle, Insurance Management and employee certifcation program in the UK so I may be abel to send you some demo's


What sort of business are you in ?

However on the print out bit,

Are you wanting to select a form and send the file (PDF is best ) to an e-mail or just save to disk ?

You can already save to file if you are using 2007 and higher, by sending all froms to preview and using 'save as'

Hope i can help

John
 
hi big bear

could u add your files here pls
especially i need to know how u creat pdf file from report and send it to email addesses

thxx
 
look for vbSendMail for sending the email
look for Stephen lebans' PDF creator
 

Users who are viewing this thread

Back
Top Bottom