weirddemon
New member
- Local time
- Today, 09:31
- Joined
- Nov 1, 2011
- Messages
- 4
I've inherited an Access application at work and I'm trying to change the email function from the old guy's email to a dummy one on the server.
I copied over the Access file and changed all references from his email to the dummy one. I tried sending an email, but received an error 438. Below is the code I'm using:
To be honest, I hate the fact that we're using VBA for a business application. It's a poor excuse for a real solution, but I think the old guy's programming knowledge was pretty awful.
From the above method, I've stripped out all the other code because it's irrelevant. The application is failing on that line. The code to the method it's calling is:
I've seen this piece of code all around the web, so I think it's fair to say he just copied and pasted it. In my searches, I found one guy who said he was having the same issue as me. He was able to turn off the macro security in Outlook and it worked.
I've done this in Outlook and Access, to no success. I don't actually think it's an error with the code since it works just fine on his old PC. I think it's an issue with the configuration of the computer, as in a security setting of some sort. I tried it on the server and my notebook, but neither worked,
Does anyone have any ideas on what's going on here?
I copied over the Access file and changed all references from his email to the dummy one. I tried sending an email, but received an error 438. Below is the code I'm using:
To be honest, I hate the fact that we're using VBA for a business application. It's a poor excuse for a real solution, but I think the old guy's programming knowledge was pretty awful.
Code:
Sub Test()
blnSuccessful = FnSafeSendEmail("email", _
"test", _
strHTML, "...", _
"...")
End Sub
From the above method, I've stripped out all the other code because it's irrelevant. The application is failing on that line. The code to the method it's calling is:
Code:
'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
I've seen this piece of code all around the web, so I think it's fair to say he just copied and pasted it. In my searches, I found one guy who said he was having the same issue as me. He was able to turn off the macro security in Outlook and it worked.
I've done this in Outlook and Access, to no success. I don't actually think it's an error with the code since it works just fine on his old PC. I think it's an issue with the configuration of the computer, as in a security setting of some sort. I tried it on the server and my notebook, but neither worked,
Does anyone have any ideas on what's going on here?