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!

Running Module

Status
Not open for further replies.

VASunGrede77

Technical User
Jun 18, 2012
8
0
0
US
I have been directed to the below site to help me with the new office e-mail security.

Have added the portion to Outlook and rand the test and all works.

But have not used modules before and having problems referencing the module in the code of the button to open and e-mail the file.
Current button code:

Private Sub Mail_Daily_Report_Click()
DoCmd.SendObject acReport, "dailylineReview", "*.pdf", "my email address removed", , , "Daily Production Report", "Attached is the current summary for production", False
End Sub

The code that has been copied into a new module named "Global Code"
Option Compare Database
Option Explicit

' ACCESS VBA MODULE: Send E-mail without Security Warning
' (c) 2005 Wayne Phillips (' Written 07/05/2005
' Last updated v1.3 - 11/11/2005
'
' Please read the full tutorial & code here:
' '
' Please leave the copyright notices in place - Thank you.

' This is a test function! - replace the e-mail addresses
' with your own before executing!!
' (CC/BCC can be blank strings, attachments string is optional)

Sub FnTestSafeSendEmail()
Dim blnSuccessful As Boolean
Dim strHTML As String

strHTML = "<html>" & _
"<body>" & _
"My <b><i>HTML</i></b> message text!" & _
"</body>" & _
"</html>"
blnSuccessful = FnSafeSendEmail("again - email address removed", _
"My Message Subject", _
strHTML)

'A more complex example...
'blnSuccessful = FnSafeSendEmail( _
"myemailaddress@domain.com; recipient2@domain.com", _
"My Message Subject", _
strHTML, _
"C:\MyAttachFile1.txt; C:\MyAttachFile2.txt", _
"cc_recipient@domain.com", _
"bcc_recipient@domain.com")

If blnSuccessful Then

MsgBox "E-mail message sent successfully!"

Else

MsgBox "Failed to send e-mail!"

End If

End Sub


'This is the procedure that calls the exposed Outlook VBA function...
Public Function FnSafeSendEmail(strTo As String, _
strSubject As String, _
strMessageBody As String, _
Optional strAttachmentPaths As String, _
Optional strCC As String, _
Optional strBCC As String) As Boolean

Dim objOutlook As Object ' Note: Must be late-binding.
Dim objNameSpace As Object
Dim objExplorer As Object
Dim blnSuccessful As Boolean
Dim blnNewInstance As Boolean

'Is an instance of Outlook already open that we can bind to?
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0

If objOutlook Is Nothing Then

'Outlook isn't already running - create a new instance...
Set objOutlook = CreateObject("Outlook.Application")
blnNewInstance = True
'We need to instantiate the Visual Basic environment... (messy)
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objExplorer = objOutlook.Explorers.Add(objNameSpace.Folders(1), 0)
objExplorer.CommandBars.FindControl(, 1695).Execute

objExplorer.Close

Set objNameSpace = Nothing
Set objExplorer = Nothing

End If



blnSuccessful = objOutlook.FnSendMailSafe(strTo, strCC, strBCC, _
strSubject, strMessageBody, _
strAttachmentPaths)

If blnNewInstance = True Then objOutlook.Quit
Set objOutlook = Nothing

FnSafeSendEmail = blnSuccessful

End Function

Really could use some help getting this to work.....
 
What error are you getting and what line is it occurring on?
 
Thats just it, think I am not properly using / addressing the module in the form. Right now, the Module is sitting there under a name of "Global Code". Then in the form, the On Click has the following
Private Sub Mail_Daily_Report_Click()

DoCmd.SendObject acReport, "dailylineReview", "*.pdf", "myemailaddress", , , "Daily Production Report", "Attached is the current summary for production", False
End Sub


What I am having trouble with is...
Referencing the "Global Code" Module in the "On Click" of the button on the form and how it works with the current Acreport feature to send the specific report.

 
Well, you have to put a function call into your form code.
at it's simplest:

if FnSafeSendEmail("someSmuck@someplace.com, _
"Hey, you Smuck!", _
"Stop calling my girl or I will punch you!", _
"c:\imagees\emergencyroom.jpg") = true then

'do something

else
'do something else

Endif
 
Well, I did find anything in the module that had "FNTESTSafe...." and replace with "FNSafeSend..." and used the following in the button...




Now, getting the error of
"Ambiguous name detected: FNSafeSendEmail"
And the highlight goes to the following portion of the module:
Public Function FnSafeSendEmail(strTo As String, _
strSubject As String, _
strMessageBody As String, _
Optional strAttachmentPaths As String, _
Optional strCC As String, _
Optional strBCC As String) As Boolean


Just wondering... has anyone gottent something like this to work? Wish I could do a 3rd party product but with how stretched things are, that will not be approved (both available time / manpower / location / budget (yes, even if it is small $'s, all is being pinched with the current market / industry)). So really limited to finding something else.
It's unfortunate, but Access is still a "taboo" product to people so really need to get this solved to make it extremely user-friendly. Otherwise, I can foresee all wanting to go back to excel (you know, everyone wants cake and eat it too, or go back to nothing and make it harder).

Again, any help is appreciated... I really want to learn this but everything I am finding on the net "assumes" you are already pretty good at modules (which, I think all agree, I am not)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top