Solved

Outlook Form VBA line error "Object Required:"

Posted on 2013-02-06
10
1,258 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 47

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 22

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 47

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 22

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 47

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 22

Author Comment

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

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 500 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 22

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

749 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