Thanks for all your advice. I actually found something really cool on
experts-exchange after I read all the (very boring) stuff about early
vs late binding. This works great!:
Dim theRef As Variant, i As Long
Dim ref As Reference, strPath98 As String, strPath00 As String
Dim strPathXP As String, strPath03 As String, strPath07 As String
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
'Update the GUID you need below.
strPath98 = "C:\Program Files\Microsoft Office\Office
\msoutl85.olb"
strPath00 = "C:\Program Files\Microsoft Office\Office\msoutl9.olb"
strPathXP = "C:\Program Files\Microsoft Office
\Office10\msoutl.olb"
strPath03 = "C:\Program Files\Microsoft Office
\OFFICE11\msoutl.olb"
strPath07 = "C:\Program Files\Microsoft Office
\OFFICE12\msoutl.olb"
'Set to continue in case of error
On Error Resume Next
'Remove any missing references
For i = 1 To Application.References.Count
Set theRef = Application.References.Item(i)
If theRef.IsBroken = True Then
Application.References.Remove (theRef)
End If
Next i
'Clear any errors so that error trapping for GUID additions can
be evaluated
Err.Clear
'Add the reference
If fs.FileExists(strPath07) Then
Application.References.AddFromFile strPath07
ElseIf fs.FileExists(strPath98) Then
Application.References.AddFromFile strPath98
ElseIf fs.FileExists(strPath03) Then
Application.References.AddFromFile strPath03
ElseIf fs.FileExists(strPath00) Then
Application.References.AddFromFile strPath00
ElseIf fs.FileExists(strPathXP) Then
Application.References.AddFromFile strPathXP
End If
'If an error was encountered, inform the user
Select Case Err.Number
Case Is = 32813
'Reference already in use. No action necessary
Case Is = vbNullString
'Reference added without issue
Case Else
'An unknown error was encountered, so alert the user
MsgBox "A problem was encountered trying to" & vbNewLine _
& "add or remove a reference in this file" & vbNewLine &
"Please check the " _
& "references in your VBA project!", vbCritical + vbOKOnly,
"Error!"
End Select
On Error GoTo 0
End Sub
On Nov 20, 7:10*am, "paii, Ron" <n...@no.comwrote:
"musicloverlch" <lho...@gmail.comwrote in message
news:c2**********************************@f40g2000 pri.googlegroups.com...
Hi all,
I have a database being used by 30 people and is split between the
backend and frontend. *The database has the ability to send e-mails
through Outlook and I have even put Redemption on people's PCs as to
not get all the Outlook security prompts. *Here's the problem: Half
are using Outlook 2003, the other half is using Outlook 2007, and 1 is
using Outlook XP. *I am using Outlook 2007, so my reference is set to
use Microsoft Outlook 12.0, but other people need Outlook 11.0
Can I programmatically have the database detect what type of Outlook
is on the PC and set the reference accordingly?
Thanks in advance,
Laura
Look at the difference between Early and Late Binding. You are using early
binding which requires a reference to Outlook. the following function uses
late binding to create and preview or send a email using Outlook. Preview
does NOT cause the security warning. With late binding, you will need to
declare any constants you wish to use.
'---------------------
' Create a email with attachments
' * stSendTo * * * Email address
' * stBody * * * * Body of the message
' * stSubject * * *Subject of the message
' * astAttach * * *Array of strings listing the path to the attachments
' * intAcount * * *Number of attachments
' * intSend * * * *True if the message should be sent without preview
Public Function EmailAttach(ByRef stSendTo As String, ByRef stBody As
String, ByRef stSubject As String, _
* * * * * * * * * * * * * * * * *astAttach() As String, intAcount As
Integer, intSend As Integer) As Integer
* * On Error GoTo errEmailAttach
* * Dim oLook As Object
* * Dim oMail As Object
* * Dim i As Integer
* * Set oLook = CreateObject("Outlook.Application")
* * Set oMail = oLook.CreateItem(0)
* * * * With oMail
* * * * * * .To = stSendTo
* * * * * * .Body = stBody
* * * * * * .Subject = stSubject
* * * * * * .ReadReceiptRequested = True
* * * * * * If intAcount <0 Then
* * * * * * * * For i = 1 To intAcount
* * * * * * * * * * .Attachments.Add (astAttach(i - 1))
* * * * * * * * Next
* * * * * * End If
* * * * * * If intSend = True Then
* * * * * * * * .Send
* * * * * * Else
* * * * * * * * .Display
* * * * * * End If
* * * * End With
* * Set oMail = Nothing
* * Set oLook = Nothing
* * EmailAttach = True
* * Exit Function
errEmailAttach:
* * MsgBox "The following error was noted : " & Err.Description & Chr$(10) &
Chr$(13) & _
* * * * * *"Your email may not have been sent.", vbCritical, "Error"
* * On Error Resume Next
* * Set oMail = Nothing
* * Set oLook = Nothing
* * EmailAttach = False
End Function