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

Sending current object in email directly from form

Status
Not open for further replies.

lmn

Programmer
Apr 3, 2003
60
US
Below is a copy of 2 different statements - that - if combined - would do exactly what I want.

The first one will look at the Project Manager and create an email (but with no attachment).

The second one will take the document I want - put it in the SNP format like I want - but not populate the person receiving, the subject line or any data in the main body section of the email.

Is there a way to make these two statements work together without 100 lines of code? The code behind the FHandle File referenced below is at the way bottom.

I'm sure this is something many many people aim to get (as it automates certain processes of emailing data to pertinent people with the click of a button.) It's not that hard to type in the email address of the recipient so the 2nd set of code (making an attachment of a SNP file) is very valuable to me, however, it would be nice if it would also do everything behind the scenes :-D

------------------
Private Sub Command10_Click()
Dim x
x = fHandleFile("mailto:" & [Forms]![Form_Bidding]!GapPMEmail, WIN_NORMAL)

End Sub
-----------------------------

Private Sub Command10_Click()

Dim stDocName As String

stDocName = "Rpt_Prospective_Bidders_Report_For_Gap_PM"
DoCmd.SendObject acReport, stDocName, acFormatSNP

End Sub
-----------------------------------------

FHandleFile

This is in the modules section of the database and is called: mdlShellExecute ------------------


Option Compare Database
Option Explicit

'************ Code Start **********
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish

Private Declare Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long

'***App Window Constants***
Public Const WIN_NORMAL = 1 'Open Normal
Public Const WIN_MAX = 2 'Open Maximized
Public Const WIN_MIN = 3 'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

'***************Usage Examples***********************
'Open a folder: ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
'Open URL: ?fHandleFile(" WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************

Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)

If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = &quot;Error: Out of Memory/Resources. Couldn't Execute!&quot;
Case ERROR_FILE_NOT_FOUND:
stRet = &quot;Error: File not found. Couldn't Execute!&quot;
Case ERROR_PATH_NOT_FOUND:
stRet = &quot;Error: Path not found. Couldn't Execute!&quot;
Case ERROR_BAD_FORMAT:
stRet = &quot;Error: Bad File Format. Couldn't Execute!&quot;
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = &quot;&quot;, vbNullString, &quot;, &quot; & stRet)
End Function
'************ Code End **********
 
Hi lmn,

Lets take the second code and modify it a little bit.

My assumptions:

1) your command button is on a form
2) their are fields on your form that defines the email address, subject lines, and main body message.

If my assumptions are correct, then we can do:

'*****begin code****

Private Sub Command10_Click()
Dim strEmail as String
Dim strSubject as String
Dim strBody as String

Dim stDocName As String

strEmail = Me!txtEmail 'name of the textbox on the form for the email address
strSubject = Me!txtSubject 'name of the textbox on the form for the subject line
strBody = Me!txtBody 'name of the textbox on the form for the body of the email



stDocName = &quot;Rpt_Prospective_Bidders_Report_For_Gap_PM&quot;
DoCmd.SendObject acSendReport, stDocName, acFormatSNP, strEmail, , , strSubject, strBody, False

End Sub
'******end code*******

hth

Have A Great Day!!!, [bigglasses]

Nathan
Senior Test Lead
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top