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

.ActiveInspector - Method or data member not found 1

Status
Not open for further replies.

tsonnenl

Programmer
Apr 8, 2002
65
US
Is there a file that needs to be referenced to use the .ActiveInspector method that I don't already have?

References already checked:
-Visual Basic for Applications
-Microsoft Access 9.0 Object Library
-OLE Automation
-Microsoft ActiveX Data Objects 2.1 Library
-Microsoft DAO 3.6 Object Library
-Microsoft Outlook 9.0 Object Library

I am trying to send an email on an event in Access and use the code from this site:

more specifically listings 1 and 4 from the article, to change the reply address to a generic 'custserv@company.com' address.

I think I must just be missing a reference, but if anyone thinks there's a problem with my cut and paste skills, I'm all ears. Thanks in advance.

Todd
 
Hi,

I don't think you've got a reference missing, it should be covered by the Outlook one. What error are you getting?

Sharon
 
Can you see the "Outlook" library in the Object Browser? If so, there should be ActiveInspector member of Application class.
 
I'm getting the "Method or data member not found" when I compile, and the .ActiveInspector gets highlighted. I also get it when the event is triggered, but the code never gets executed because of the compile error.

I recently noticed that in that article that I listed above that there are user comments at the bottom where another user seems to have had my same problem, and what could be the person who originally posted the code responded that the code wouldn't work if Outlook used Word to edit email messages. I checked this and I do not, but I still have the problem.
 
Yes, the outlook library and the .ActiveInspector method are in the object browser. So if there is no referencing problem, why would I get a compile error?
 
Post the relevant bit of your code - maybe it's something about the way you're setting things up.
Rob
[flowerface]
 
You asked for it. The error occurs in the 5th line of the ChangeReplyAddrNoPrompt() function.

Private Sub Confirmed_Click()
If Me.Confirmed = True Then
Me.DateLocalConfirmed = Date

wantsnotification = DLookup("WantsEmail", "tblCustomers", "CustID = " & Me.CustID)
If wantsnotification = True Then
emailaddress = DLookup("Email", "tblCustomers", "CustID = " & Me.CustID)

message = "Your " & Me.OrderType & " order has been confirmed. The work will be completed on " & Me.DueDate & "."

fctnOutlook "custservice@gtb.net", emailaddress, , , "Order Confirmation", message, , 1, False
End If
Else
Me.DateLocalConfirmed = ""
End If

Function fctnOutlook(Optional FromAddr, Optional Addr, Optional CC, Optional BCC, _
Optional Subject, Optional MessageText, Optional Vote As String = vbNullString, _
Optional Urgency As Byte = 1, Optional EditMessage As Boolean = True)

' Code sample from Accessory
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

Dim colReplyRecips As Recipients
Dim objReplyRecip As Recipient

With objOutlookMsg

If Not IsMissing(FromAddr) Then
.SentOnBehalfOfName = FromAddr
ChangeReplyAddrNoPrompt

End If

If Not IsMissing(Addr) Then
Set objOutlookRecip = .Recipients.Add(Addr)
objOutlookRecip.Type = olTo
End If

If Not IsMissing(CC) Then
Set objOutlookRecip = .Recipients.Add(CC)
objOutlookRecip.Type = olCC
End If

If Not IsMissing(BCC) Then
Set objOutlookRecip = .Recipients.Add(BCC)
objOutlookRecip.Type = olBCC
End If

If Not IsMissing(Subject) Then
.Subject = Subject
End If

If Not IsMissing(MessageText) Then
.Body = MessageText
End If

If IsNull(Vote) = False Then
.VotingOptions = Vote
End If

Select Case Urgency
Case 2
.Importance = olImportanceHigh
Case 0
.Importance = olImportanceLow
Case Else
.Importance = olImportanceNormal
End Select

For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

If EditMessage Then
.Display
Else
.Save
.Send
End If

End With
Set objOutlook = Nothing

End Function

Sub ChangeReplyAddrNoPrompt()
Dim objApp As Application
Dim objItem As MailItem
Dim strRecipName As String

Set objApp = CreateObject("Outlook.Application")
Set objItem = objApp.ActiveInspector.CurrentItem

' ### USER OPTION - specify reply address ###
strRecipName = "custservice@gtb.net"
If objItem.Class = olMail And _
objItem.Sent = False Then
Call AddReplyRecip(objItem, strRecipName)
End If

Set objItem = Nothing
Set objApp = Nothing
End Sub

Private Sub AddReplyRecip(objMsg As MailItem, strName As String)
Dim colReplyRecips As Recipients
Dim objReplyRecip As Recipient
Dim strPrompt As String
Dim intRes As Integer
Dim strRecipName As String

Set colReplyRecips = objMsg.ReplyRecipients
Set objReplyRecip = colReplyRecips.Add(strName)
objReplyRecip.Resolve
If Not objReplyRecip.Resolved Then
objReplyRecip.Delete
strPrompt = Quote(strName) & " could not be resolved as " & _
"a valid Outlook address. Do you want to try " & _
"a different name?"
intRes = MsgBox(strPrompt, _
vbYesNo + vbQuestion + vbDefaultButton1, _
"Try Again?")
If intRes = vbYes Then
strRecipName = GetReplyAddress(objMsg)
If strRecipName <> &quot;&quot; Then
Call AddReplyRecip(objMsg, strRecipName)
End If
End If
End If

Set colReplyRecips = Nothing
Set objReplyRecip = Nothing
End Sub
 
You need:
Dim objApp As outlook.Application
Dim objItem As outlook.MailItem
Rob
[flowerface]
 
Ok, that got rid of the compile error, but I still get a &quot;Object variable or With block variable not set&quot; error on the same line.
 
You probably have no active inspector when that call is made. In that case, there is no CurrentItem, hence the error.
Rob
[flowerface]
 
Shouldn't it recognize the &quot;Set objOutlookMsg = objOutlook.CreateItem(olMailItem)&quot; line that was already executed in the function above it? I'm not very familiar with the ActvieInspector method but from what I have read and more importantly what I am trying to do, isn't the currentitem that I want to change the email that was generated in the previous function?
 
You invoked a new instance of Outlook, I think, in the createobject call just above the problem statement. This new instance has no active inspector. Try setting the Outlook application variable just once, in an initialization sub, as a public variable.
Rob
[flowerface]
 
Finally!! I took the code from the problem function and placed it where it was previously referenced to eliminate those issues discussed above, and the second instance of the outlook object was removed. Thanks for your time Rob, have a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top