Solved

Outlook Form VBA line error "Object Required:"

Posted on 2013-02-06
10
1,202 Views
Last Modified: 2013-02-06
I created a custom form with two buttons
CommandButtonAPP & CommandButtonDeny

I want to be able to toggle them from being Enable to Disabled, but when I run the form I get "Object Required: CommandButtonApp"

Here is my code: Not this is from Script Editor in OUTLOOK.
 

Sub Item_AttachmentAdd(ByVal NewAttachment)
If item.attachments.count > 0 then 
CommandButtonAPP.Enable = -1
CommandButtonDENY.Enable = -1
End if
End Sub





Sub CommandButtonAPP_Click()
Set objItem = GetCurrentItem()
Set objMail = objItem.Forward
objMail.To = item.SenderEmailAddress
objMail.Body =  "Invoice(s) attached to the e-mail have been APPROVED"
'objMail.send
objMail.Display
Set objItem = Nothing
Set objMail = Nothing
End Sub

Sub CommandButtonDENY_Click()
Set objItem = GetCurrentItem()
Set objMail = objItem.Forward
objMail.To = item.SenderEmailAddress
objMail.Body =  "Invoice(s) attached to the e-mail have been Denied"
'objMail.send
objMail.Display
Set objItem = Nothing
Set objMail = Nothing
End Sub


   
Function GetCurrentItem() 
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = _
objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = _
objApp.ActiveInspector.CurrentItem
Case Else
End Select
End Function
   
    
    

Open in new window

0
Comment
Question by:yo_bee
  • 4
  • 4
  • 2
10 Comments
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
I assume the error is occurring on line 3. Is the Item_AttachmentAdd sub on the same form as CommandButtonApp? If not then change line 3 to

YourFormName.CommandButtonAPP.Enable = -1
0
 
LVL 21

Author Comment

by:yo_bee
Comment Utility
Now instead of CommandButtonApp in the error Message it is the Form name in the error message Invoices_For_Approval
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
I don't see "Invoices_For_Approval" in your code.
0
 
LVL 21

Author Comment

by:yo_bee
Comment Utility
I added it after your first reply.

Sub Item_AttachmentAdd(ByVal NewAttachment)
If item.attachments.count > 0 then 
Invoices_for_Approval.CommandButtonAPP.Enable = -1
Invoices_for_Approval.CommandButtonDENY.Enable = -1
End if
End Sub

Open in new window

0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Sorry, still don't see it but is "Invoices_for_Approval" the exact name of the form?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 21

Author Comment

by:yo_bee
Comment Utility
Where Would I find this Exact Name?
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
I've never actually created a form in Outlook but this article shows, among other things, how forms are created. Using that info you should be able to see all your forms and their names.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
Hi, yo_bee.

Try this code.

Sub Item_Open()
    If Item.Attachments.Count > 0 then
        SetButtonState True
    Else
        SetButtonState False
    End if
End Sub

Sub CommandButtonAPP_Click()
    TakeAction "approved"
End Sub

Sub CommandButtonDENY_Click()
    TakeAction "denied"
End Sub
   
Sub TakeAction(strAction)
    Dim objMail, objItem
    Set objMail = Item.Forward
    With objMail
        .To = Item.SenderEmailAddress
        .Body =  "Invoice(s) attached to the e-mail have been " & strAction
        '.send
        .Display
    End with
    Set objItem = Nothing
    Set objMail = Nothing
End Sub

Sub SetButtonState(bolState)
    dim objPage, objCntl
    Set objPage = Item.GetInspector.ModifiedFormPages
    Set objCntl = objPage("P.2").Controls("CommandButtonAPP")
    objCntl.Enabled = bolState
    Set objCntl = objPage("P.2").Controls("CommandButtonDENY")
    objCntl.Enabled = bolState
    Set objPage = Nothing
    Set objCntl = Nothing
End Sub

Open in new window

0
 
LVL 21

Author Closing Comment

by:yo_bee
Comment Utility
If I could give you more points I would.
I was looking at ModifiedFormPage as something, but I could not put my finger on it.
To boot you even streamlined it for me to by removing unnecessary lines of code.

 

Well Done good friend
Many thanks
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're welcome!  Glad I could help out.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now