Solved

Outlook Form VBA line error "Object Required:"

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

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 48

Expert Comment

by:Martin Liss
ID: 38861139
I don't see "Invoices_For_Approval" in your code.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 48

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 48

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
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…
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…

695 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