A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Command Button Controls



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 7th 10, 05:45 PM posted to microsoft.public.outlook.program_forms
Ashley[_2_]
external usenet poster
 
Posts: 5
Default Command Button Controls

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  
Old April 7th 10, 10:15 PM posted to microsoft.public.outlook.program_forms
Hollis Paul
external usenet poster
 
Posts: 242
Default Command Button Controls

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  
Old April 7th 10, 10:19 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP][_4_]
external usenet poster
 
Posts: 552
Default Command Button Controls

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  
Old April 8th 10, 05:08 PM posted to microsoft.public.outlook.program_forms
Ashley[_2_]
external usenet poster
 
Posts: 5
Default Command Button Controls

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  
Old April 8th 10, 05:30 PM posted to microsoft.public.outlook.program_forms
Ashley[_2_]
external usenet poster
 
Posts: 5
Default Command Button Controls

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  
Old April 10th 10, 10:10 PM posted to microsoft.public.outlook.program_forms
Hollis Paul
external usenet poster
 
Posts: 242
Default Command Button Controls

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
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 03:35 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.