PC Review


Reply
Thread Tools Rate Thread

Command Button Controls

 
 
Ashley
Guest
Posts: n/a
 
      7th Apr 2010
I created a command button on my custom form and when its clicked I want the following code to run. here is my code, but nothing happens when I click on the button. I know my code works when I run it mannually.

Thanks


Sub CommandButton1_Click()
Dim item As MailItem

' Set item = Outlook.Application.ActiveExplorer.Selection.item(1)
Set item = Outlook.Application.ActiveInspector.CurrentItem



Dim olApp As Outlook.Application
Dim olTsk As TaskItem
Dim userField As Outlook.UserProperty

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)


With olTsk
.Subject = item.Subject
.Status = olTaskNotStarted
.Body = item.Body
Set ups = item.UserProperties
Set prp = ups.Find("DateDue")
.DueDate = ups("DateDue").Value


.Save
End With

Set olTsk = Nothing
Set olApp = Nothing
End Sub.
Submitted using http://www.outlookforums.com
 
Reply With Quote
 
 
 
 
Sue Mosher [MVP]
Guest
Posts: n/a
 
      7th Apr 2010
This looks like VBA code, not VBScript behind a custom Outlook form. Please
clarify.

Note that code runs only on published Outlook custom forms.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54



"Ashley" wrote:

> I created a command button on my custom form and when its clicked I want the following code to run. here is my code, but nothing happens when I click on the button. I know my code works when I run it mannually.
>
> Thanks
>
>
> Sub CommandButton1_Click()
> Dim item As MailItem
>
> ' Set item = Outlook.Application.ActiveExplorer.Selection.item(1)
> Set item = Outlook.Application.ActiveInspector.CurrentItem
>
>
>
> Dim olApp As Outlook.Application
> Dim olTsk As TaskItem
> Dim userField As Outlook.UserProperty
>
> Set olApp = New Outlook.Application
> Set olTsk = olApp.CreateItem(olTaskItem)
>
>
> With olTsk
> .Subject = item.Subject
> .Status = olTaskNotStarted
> .Body = item.Body
> Set ups = item.UserProperties
> Set prp = ups.Find("DateDue")
> .DueDate = ups("DateDue").Value
>
>
> .Save
> End With
>
> Set olTsk = Nothing
> Set olApp = Nothing
> End Sub.
> Submitted using http://www.outlookforums.com
> .
>

 
Reply With Quote
 
Ashley
Guest
Posts: n/a
 
      8th Apr 2010
I guess I was using VBA, I have never programmed in Outlook always access and excel. I wrote the code and can call the macro from the Developer Tab (Marcos). I tried pasteing the code where it allows you to under the form code (View Code). I rewrote my code, it still works calling it like a marco but I can't get it to assign to my button. Help!


Public Sub CommandButton1_Click()

Set ins = Application.ActiveInspector
Set itm = ins.CurrentItem

If itm.Class <> olMail Then
MsgBox "The active Inspector is not a mail message; exiting"
' GoTo ErrorHandlerExit
'Could add more error-trapping to determine if the mail message uses a
'specific custom form, or has specific data in one or more fields

Else
Set msg = itm


' Set item = Outlook.Application.ActiveExplorer.Selection.item(1)
'Set item = Outlook.Application.ActiveInspector.CurrentItem



Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)


With olTsk
.Subject = msg.Subject
.Status = olTaskNotStarted
.Body = msg.Body
Set ups = msg.UserProperties
Set prp = ups.Find("DateDue")
If TypeName(prp) <> "Nothing" Then
If prp.Value <> #1/1/4501# Then
.DueDate = ups("DateDue").Value
End If
End If


.Save
End With

Set olTsk = Nothing
Set olApp = Nothing
End If
End Sub.
Submitted using http://www.outlookforums.com
 
Reply With Quote
 
Ashley
Guest
Posts: n/a
 
      8th Apr 2010
Ok, so here is my code now, Doesn't give me an error but it doesn't run.


Public Sub CommandButton1_Click()


Set ins = Outlook.Inspector
Set itm = Object
Set ups = Outlook.UserProperties
Set prp = Outlook.UserProperty
Set msg = Outlook.MailItem
Set olApp = Outlook.Application
Set olTsk = TaskItem
Set userField = Outlook.UserProperty
Set ins = Application.ActiveInspector
Set itm = ins.CurrentItem

If itm.Class <> olMail Then
MsgBox "The active Inspector is not a mail message; exiting"

Else
Set msg = itm



Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)


With olTsk
.Subject = msg.Subject
.Status = olTaskNotStarted
.Body = msg.Body
Set ups = msg.UserProperties
Set prp = ups.Find("DateDue")
If TypeName(prp) <> "Nothing" Then
If prp.Value <> #1/1/4501# Then
.DueDate = ups("DateDue").Value
End If
End If


.Save
End With

Set olTsk = Nothing
Set olApp = Nothing
End If
End Sub

 
Reply With Quote
 
Sue Mosher [MVP]
Guest
Posts: n/a
 
      15th Apr 2010
Is the button named CommandButton1?

Is the form published with the "Send form definition with item" box on the
(Properties) page unchecked?

None of these expressions will work -- Outlook.UserProperties,
Outlook.Inspector , etc. -- because there is no intrinsic object named
Outlook. As Hollis pointed out, in VBScript code behind a custom form, you
have two intrinsic objects: Application for the currently running
Outlook.Application instance (hence you never would use New
Outlook.Application) and Item to represent the item where the code is
running.

I can't offer much more than that, because I can't tell from the code just
what you're trying to accomplish.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54



"Ashley" wrote:

> Ok, so here is my code now, Doesn't give me an error but it doesn't run.
>
>
> Public Sub CommandButton1_Click()
>
>
> Set ins = Outlook.Inspector
> Set itm = Object
> Set ups = Outlook.UserProperties
> Set prp = Outlook.UserProperty
> Set msg = Outlook.MailItem
> Set olApp = Outlook.Application
> Set olTsk = TaskItem
> Set userField = Outlook.UserProperty
> Set ins = Application.ActiveInspector
> Set itm = ins.CurrentItem
>
> If itm.Class <> olMail Then
> MsgBox "The active Inspector is not a mail message; exiting"
>
> Else
> Set msg = itm
>
>
>
> Set olApp = New Outlook.Application
> Set olTsk = olApp.CreateItem(olTaskItem)
>
>
> With olTsk
> .Subject = msg.Subject
> .Status = olTaskNotStarted
> .Body = msg.Body
> Set ups = msg.UserProperties
> Set prp = ups.Find("DateDue")
> If TypeName(prp) <> "Nothing" Then
> If prp.Value <> #1/1/4501# Then
> .DueDate = ups("DateDue").Value
> End If
> End If
>
>
> .Save
> End With
>
> Set olTsk = Nothing
> Set olApp = Nothing
> End If
> End Sub
>
> .
> Submitted using http://www.outlookforums.com
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Command Button Controls Harriet Microsoft Access 0 21st May 2009 05:16 PM
Command Button Active X controls =?Utf-8?B?S2Vubnk=?= Microsoft Excel Misc 1 2nd Oct 2007 02:39 AM
Transparent Command Button & DBPix controls Martijn van Meeteren Microsoft Access Forms 1 2nd Mar 2007 11:21 PM
Excel Add-In with Command Button Controls Mark Dev Microsoft Excel Programming 4 24th May 2005 08:14 PM
command button & controls koko Microsoft Access Forms 0 16th Dec 2003 06:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.