![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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 |
Ads |
#2
|
|||
|
|||
![]()
In article , Ashley wrote:
Dim item As MailItem It looks to me like you are trying to run VBA code in the form, when the form will only run VBScript. In the versions I used, "Dim AS" did not work. -- Hollis Paul Mukilteo, WA USA |
#3
|
|||
|
|||
![]()
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 . |
#4
|
|||
|
|||
![]()
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 |
#5
|
|||
|
|||
![]()
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 |
#6
|
|||
|
|||
![]()
In article , Ashley wrote:
Ok, so here is my code now, Doesn't give me an error but it doesn't run. The best source for Outlook coding is http://www.outlookcode.com . You will find example code for things you may want to do, but certainly examples of how to style the code. For instance, Item is an intrinsic variable, and always means the current Item. I seem to recall that Application is also an intrinsic item, and you use it as the basis for building objects. But, it has been a while since I did any coding, so I am not going to provide specific coding suggestions. Go look at the examples. -- Hollis Paul Mukilteo, WA USA |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Command Button | BellG | Outlook - Using Forms | 1 | February 25th 09 03:06 PM |
Command Button | [email protected] | Outlook - Using Forms | 12 | January 18th 08 05:57 PM |
Command Button Opens the Webpage only once | Marilyn | Outlook - Using Forms | 0 | December 19th 07 07:19 PM |
Command Button | Daniel Vargas | Outlook - Using Forms | 1 | May 23rd 07 09:35 PM |
command button and multipage | snwooz | Outlook - Using Forms | 1 | November 1st 06 07:26 PM |