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

outlook 2010 simple question

Status
Not open for further replies.

Turtleman10

Technical User
Sep 13, 2012
40
US
I am using some very simular code in outlook to change the subject line. When I try to use it in this instance I get an error on the object Outlook.Application.ActiveInspector.currentItem. I can use the object Outlook.Application but its not going to do what I need it to do. Any ideas?

Code:
Private Sub Accept_Click()


Dim Item As Outlook.Application
Set Item = New Outlook.Application

'Set Item = New Outlook.Application.ActiveInspector.currentItem

            
            
            
        Item.Subject = "PN_" + tbPartN + "_SD_" + tbShipDT + "_PO_" + tbPO
        
        strSubjectA = strA + tbShipDT + tbPartN + tbRev + ".PDF"
        
'Copy attachment for Kohler
       
            For Each ITEM2 In objSel
    
             Set myAttachments = ITEM2.Attachments
         
                If myAttachments.Count > 0 Then
 
                    For i = 1 To myAttachments.Count
                    myAttachments(i).SaveAsFile myOrtK & strSubjectA
                    Next
                End If
            Next
    
'Chance to cancel E-mail if it was a mistake
    
    Prompt$ = "Do you want to send this Cert to Kohler?"
        If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Attachment") = vbNo Then
        Cancel = True
        Exit Sub
        End If


End Sub
 
Hi,

It looks to me that you have tried two approaches, dim'ed Item as Access.Application then tried to set it as

New Outlook.Application.ActiveInspector.currentItem

Which wont work as the types are different

Or

tried to use the Item.Subject which is effectively Outlook.Application.Subject (which doesn't exist).

if you keep Item defined as Outlook.Application you then need your Subject allocation to be

Item.ActiveInspector.currentItem.Subject = "PN_" + tbPartN + "_SD_" + tbShipDT + "_PO_" + tbPO

hope this helps, Graham



There are two ways to write error-free programs; only the third one works.
 
Ok I have it working now. Things to keep in mind. Set Item = Application.ActiveInspector.currentItem you cannot have outlook.application when you set it I dont know why but if you take out outlook it works and also if you are doing an inspect remember to have an E-mail open otherwise it will fail and you will want to slap yourself when you figure out you didnt have anything open to inspect.



Code:
Private Sub Accept_Click()

Kohler.Hide

'Declaration
Dim strSubject As String
Dim strSubjectA As String
Dim tbPartN As String
Dim tbPO As String
Dim tbRev As String
Dim tbShipDT As String
Dim myOrtK As String
Dim strA As String
Dim Prompt$
Dim Item As Outlook.MailItem
Set Item = Application.ActiveInspector.currentItem
Set objApp = CreateObject("Outlook.Application")
Set objEXP = objApp.ActiveExplorer
Set objSel = objEXP.Selection

tbPartN = PartNumber
tbPO = PO
tbRev = Revision
tbShipDT = ShipDate


With Item

'Destination Folder
    myOrtK = "R:\CERTS\KOHLER\"
    
'    On Error Resume Next
    
'strSubject = Item.Subject
strA = "KECCERT"
        
'Create subjectline for Kohler
            
        Item.Subject = "PN_" + tbPartN + "_SD_" + tbShipDT + "_PO_" + tbPO + tbRev
        
        strSubjectA = strA + tbShipDT + tbPartN + tbRev + ".PDF"
        
'Copy attachment for Kohler
       
            For Each ITEM2 In objSel
    
             Set myAttachments = ITEM2.Attachments
         
                If myAttachments.Count > 0 Then
 
                    For i = 1 To myAttachments.Count
                    myAttachments(i).SaveAsFile myOrtK & strSubjectA
                    Next
                End If
            Next
    
'Chance to cancel E-mail if it was a mistake
    
    Prompt$ = "Do you want to send this Cert With this subject line?" + Item.Subject
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Attachment") = vbNo Then
    Cancel = True
    Exit Sub
    End If
    
End With

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top