Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Outlook Form VBA line error "Object Required:"

Posted on 2013-02-06
10
Medium Priority
?
1,317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38861063
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 23

Author Comment

by:yo_bee
ID: 38861114
Now instead of CommandButtonApp in the error Message it is the Form name in the error message Invoices_For_Approval
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38861139
I don't see "Invoices_For_Approval" in your code.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 23

Author Comment

by:yo_bee
ID: 38861152
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 49

Expert Comment

by:Martin Liss
ID: 38861175
Sorry, still don't see it but is "Invoices_for_Approval" the exact name of the form?
0
 
LVL 23

Author Comment

by:yo_bee
ID: 38861201
Where Would I find this Exact Name?
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38861231
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 2000 total points
ID: 38862370
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 23

Author Closing Comment

by:yo_bee
ID: 38862410
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
ID: 38862435
You're welcome!  Glad I could help out.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

618 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