Command Button Controls

Status
Not open for further replies.
A

Ashley

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.
 
In article <OX35NHn1KHA.5880@TK2MSFTNGP05.phx.gbl>, 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
 
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
 
Re: RE: 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.
 
Re: RE: 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
 
In article <uCwa9iz1KHA.5004@TK2MSFTNGP05.phx.gbl>, 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
 
Re: RE: Command Button Controls

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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
bdsermons Outlook 365 command button in outlook form Outlook VBA and Custom Forms 5
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
J Command Button to stamp a date and time in a textbox in Outlook 2016 Outlook VBA and Custom Forms 3
D Command Button code will not execute. Any suggestions Please. Outlook VBA and Custom Forms 2
S Problem running Command button code Outlook VBA and Custom Forms 2
S Code behind form command button Using Outlook 2
M Open new outlook form from within existing outlook form using command button Using Outlook 4
J Command Button to insert Email Signature Outlook VBA and Custom Forms 2
Z Command button no longer firing after sending custom form over ema Outlook VBA and Custom Forms 1
U Customized Command Button Outlook VBA and Custom Forms 3
M Move command Outlook VBA and Custom Forms 11
S Command Button_Click action on Item/Reminder Outlook VBA and Custom Forms 3
J OUTLOOK 2016 FILE STORAGE WHERE COMMAND Using Outlook 12
D Custom Form Accept and Reject Command buttons Outlook VBA and Custom Forms 2
Dr. Demento Outlook version of Excel command? Using Outlook 5
L Outlook Data Files command not working in the quick access bar Using Outlook 1
R Missing Backup command in File menu after installing pfback.exe Using Outlook 2
S Exchange Management Shell closes on command failure Exchange Server Administration 5
M "New Appointment from Contact" command missing from Outlook 2003 Using Outlook 1
J Executing Ribbon Command from Code Outlook 2010 Outlook VBA and Custom Forms 3
S How to call a procedure from a custom command bar in Outlook 2007 Outlook VBA and Custom Forms 1
L Outlook 2003 - Set Virables via command line Outlook VBA and Custom Forms 1
T Command bar IDs for Outlook 2007 Using Outlook 2
T Is there a VBA command to Redirect your Emails? Outlook VBA and Custom Forms 1
A How to access command bars in outlook 2007 Outlook VBA and Custom Forms 3
5 How to get Outlook's command line parameters? Outlook VBA and Custom Forms 1
G Add Map It button to Custom Contacts Form in Outlook Outlook VBA and Custom Forms 1
J Outlook 2021 ScanPST errors (yet again ... sorry): repair button missing Outlook 2021 Using Outlook 5
S Outlook 2002- "Send" button has disappeared. Help please. Using Outlook 1
TomHuckstep Remove Send/Receive All Folders (IMAP/POP) button from Outlook 365 Ribbon Using Outlook 2
Witzker How to get the button Karte ( map) in custom contact form Outlook VBA and Custom Forms 2
J Want to create a button on the nav bar (module add-in) to run code Outlook VBA and Custom Forms 2
B How to create a button that sorts and selects the most recent message with ONE click Using Outlook 2
jehan2256 "History" button in Business Contact Manager Using Outlook 1
L "Insert Pictures" Button-Wrong Folder Using Outlook 5
O Replace hard returns with soft returns on selected text and button to QAT Using Outlook 5
J "Contact" button in Journal entry Using Outlook 1
O Outlook 2010 Add delete button to the side of the message list Using Outlook 1
I Button PDF in Outlook Contact custom form Outlook VBA and Custom Forms 1
D Outlook 2013 Macros only run in VB editor, not in drop down or button Outlook VBA and Custom Forms 14
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
Witzker HowTo start a macro with an Button in OL contact form Outlook VBA and Custom Forms 12
R Follow up button doesn't working neither the reminders in BCM BCM (Business Contact Manager) 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
K Disabling import/export button to restrict PST creation Using Outlook 3
N Which Button Was Clicked on the Ribbonbar Menu Outlook VBA and Custom Forms 2
E Can't accept or decline task (no button appears) Using Outlook 2
Q Prompt button to auto turn on Out of Office Outlook VBA and Custom Forms 3
C iCloud Setting missing Outlook tab and Outlook missing the iCloud refresh button Using Outlook 4
Witzker Outlook 2010 Insert Date & Time at the button of an OL contactform in red Using Outlook 2

Similar threads

Back
Top