?
Solved

Outlook Form VBA line error "Object Required:"

Posted on 2013-02-06
10
Medium Priority
?
1,296 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
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!

 
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

801 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