command button starting a customized form

V

Veggatron

i have some customized outlook forms in a test-environment (a .PS
called testenvironment) and what i want is the following:

when pressing a commandbutton on 1 form (a contact-form with data fro
my customers) i want to start a customized-task.

so:
when on customized form
press button
then
start customized task

can anyone help we with code and form-management ?

thnx. hope this has been clear. i'm using outlook2000 btw
 
V

Veggatron

i'm not sure, but is that a button on a toolbar? i am looking for
commandbutton on a custom form. i'll play around with it, maybe you ca
give me some more clues
 
V

Veggatron

i'm not sure, but is that a button on a toolbar? i am looking for
commandbutton on a custom form. i'll play around with it, maybe you ca
give me some more clues
 
S

Sue Mosher [MVP-Outlook]

The syntax for launching a form is the same regardless of where the code is
running. Or are you unclear on how to write code for a form button?

Also note: The newsgroup interface you are using apparently does not quote
earlier messages in the thread, making your latest message so short on
detail that you risk not getting the answer you're looking for. Please take
the time to quote the original message.
 
V

Veggatron

Code
-------------------

Sub RunMyForm()
Dim myOlApp as Application
Dim myNameSpace as Namespace
Dim myFolder as MAPIFolder
Dim myItems as Items
Dim myItem as Object

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = _
myNamespace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
Set myItem = myItems.Add("IPM.Task.MyForm")
myItem.Display

Set myOlApp = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myItems = Nothing
Set myItem = Nothing
End Sub

-------------------


i got this piece of code, but how do i assign that to a commandbutto
on my custom form? i know how to add it to the toolbar, but i can'
just drag and drop the macro on my form of course.
can you help me with this as well?

i'm not using a newsgroup, i'm posting on outlookforum.com, i'll repl
with quotes...
 
S

Sue Mosher [MVP-Outlook]

This code is VBA. Outlook form code is VBScript. Before you can use it on a
form, you will need to clean it up as follows:

1) Replace the myOlApp object with Application, which is an intrinsic object
in Outlook form script.

2) Remove the typed variable declarations (e.g. "as Application).

3) Either declare constants for the Outlook constants (e.g. olFolderTasks)
or use their literal values, which you can look up in the object browser.

Once you make those changes, you can add the code to the form's script using
the View Code command in form design mode and run it from a command button's
click event:

Sub CommandButton1_Click()
Call RunMyForm
End Sub

FYI, you *are* using a newsgroup. Outlookforum.com simply provides a web
interface (and not a great one, IMO) to the newsgroups.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
V

Veggatron

Sue, thnx for your patience and your time. i'm pretty new with this a
you might already have figured out.

so i'm not sure what to do wiht #3. and i'm positive about the fac
that i didnt do the right things with #1 and #2.

the folder that contains IPM.Task is called "Taken"


Code
-------------------

Sub CommandButton1_Click()
Call RunMyForm
End Sub

Sub RunMyForm()

Option Explicit

Dim Application
Dim myNameSpace
Dim myFolder
Dim myItems
Dim myItem
Dim myObject

Set Application = CreateObject("Outlook.Application")
Set myNameSpace = Application.GetNameSpace("MAPI")
Set myFolder = _
myNameSpace.GetDefaultFolder(olFolderTaken)
Set myItems = myFolder.Items
Set myItem = myItems.Add("IPM.Task")
myItem.Display

Set Application = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myItems = Nothing
Set myItem = Nothing

End Sub
 
V

Veggatron

Sue, thnx for your patience and your time. i'm pretty new with this a
you might already have figured out.

so i'm not sure what to do wiht #3. and i'm positive about the fac
that i didnt do the right things with #1 and #2.

the folder that contains IPM.Task is called "Taken"


Code
-------------------

Sub CommandButton1_Click()
Call RunMyForm
End Sub

Sub RunMyForm()

Option Explicit

Dim Application
Dim myNameSpace
Dim myFolder
Dim myItems
Dim myItem
Dim myObject

Set Application = CreateObject("Outlook.Application")
Set myNameSpace = Application.GetNameSpace("MAPI")
Set myFolder = _
myNameSpace.GetDefaultFolder(olFolderTaken)
Set myItems = myFolder.Items
Set myItem = myItems.Add("IPM.Task")
myItem.Display

Set Application = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myItems = Nothing
Set myItem = Nothing

End Sub
 
S

Sue Mosher [MVP-Outlook]

You're almost there!

1) Again, Application and Item are *intrinsic* objects in form script. You
don't declare them. You don't instantiate them. You just use those objects.
Take out the Dim Application and Set Application statements.

2) You did fine on removing the typed variable declarations.

3) Learn to use the object browser. Press ALt+F11 to open the VBA
environment in Outlook, then press F2. You're now looking at all the
objects, etc. for Outlook. To look up the literal value for the
olFolderTasks constant, type that constant name into the empty box next to
the button with the binoculars (the Find button) and then click the
binoculars. You will olFolderTasks in the Member column of the search
results and can then see its literal value (13) at the bottom of the window.
You'll also see the full text of a Const declaration statement that you can
copy and paste into the declarations section of your procedure, so you can
continue to use olFolderTasks in your code (but you'll need to correct it in
your code below where you have olFolderTaken instead).

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
V

Veggatron

Sue, thnx for the help on the constant-declaration.
We've decided to add a custom command bar. i'll add the code here, i
may be useful for someone else.

when i have more issues i'll post them here :)

Code
-------------------

Sub cmdTaakVerkoop_Click()

Dim objFolder
Dim objItem
Dim strMsgClass
Dim strFolderPath

If mblnReadFromFolder Then
mblnReadFromFolder = False
End If

WriteRegister

'where Testomgeving 2502 is the name of the .PST and

strFolderPath = "Testomgeving 2502/Taken Verkoop TO"



strMsgClass = "IPM.Task.TakenVerkoopTest2502"

If strFolderPath = "" Then
Set objFolder = UserDefaultFolder(Item.UserProperties("FormType").Value)
Else

Set objFolder = GetMAPIFolder(strFolderPath)

End If

If Not objFolder Is Nothing And strMsgClass <> "" Then
On Error Resume Next
Set objItem = objFolder.Items.Add(strMsgClass)
objItem.Display
Else
MsgBox "Could not locate " & strFolderPath & " folder.", , "Problem finding folder"
End If

Item_Open = False

Set objItem = Nothing
Set objFolder = Nothing


End Sub

-------------------



*You're almost there!

1) Again, Application and Item are *intrinsic* objects in for
script. You
don't declare them. You don't instantiate them. You just use thos
objects.
Take out the Dim Application and Set Application statements.

2) You did fine on removing the typed variable declarations.

3) Learn to use the object browser. Press ALt+F11 to open the VBA
environment in Outlook, then press F2. You're now looking at all the
objects, etc. for Outlook. To look up the literal value for the
olFolderTasks constant, type that constant name into the empty bo
next to
the button with the binoculars (the Find button) and then click the
binoculars. You will olFolderTasks in the Member column of th
search
results and can then see its literal value (13) at the bottom of th
window.
You'll also see the full text of a Const declaration statement tha
you can
copy and paste into the declarations section of your procedure, s
you can
continue to use olFolderTasks in your code (but you'll need t
correct it in
your code below where you have olFolderTaken instead).

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top