How can I add a command button to open up a new form?

M

Mike

I am extremely limited in my programming skills, but desperately need to open
up a modified version of the "Post" template up from a command button on a
modified "Contact" form. The new form also needs to be prepopulated.

I have created both new forms and saved them, but I have been unable to
figure out how to correctly setup the command button on the "Contact" form to
open up the "Post" form. I have both forms in seperate Public Folders on my
Exchange Server and in the Properties on the folder in which the modified
"Contact" form resides, I have setup the "Activities" to look for the "Post"
items in the other public folder.

I cannot seem to find the answers I am looking for in opther threads, so
please forgive me if I am being repetitive, here!

Ultimately, I need to have a command button that opens up a new form and
"passes" it a parameter (in this case the Contact or Contacts) for the new
form to be pre-populated.

If anyone knows of any sample .oft that I could model after or any resources
that I may have missed - please help!!!
 
S

Sue Mosher [MVP-Outlook]

To create a new instance of a custom form programmatically, use the Add method on the target folder's Items collection. If it's a message form, you can use the Drafts folder as the target. If the target is a default folder, you can use the Namespace.GetDefaultFolder method to return it as a MAPIFolder object. Otherwise, you can use the code at http://www.outlookcode.com/d/code/getfolder.htm to walk the folder hierarchy and return the MAPIFolder corresponding to a given path string.
 
M

Mike

Thank you for your help! I can now open a new (different) from from a
command button, but I am still not sure how to have the form open with a
value from the original form "prepopulated."

In my case, I am opening up a new note form from a modified Contact from and
would like to have the "Contact" value in the new form filled out
automatically when the new Note form is launched from the original form - Is
this possible?

Here is my current code to open the new note form from a command button:

Sub CommandButton1_Click()
Set olns = Item.Application.GetNameSpace("MAPI")
Set MyFolder1 = olns.Folders("Public Folders")
Set MyFolder2 = MyFolder1.Folders("All Public Folders")
Set MyFolder3 = MyFolder2.Folders("Shamrock")
Set MyFolder4 = MyFolder3.Folders("General")
Set MyFolder5 = MyFolder4.Folders("Customer Notes")
Set MyItem = MyFolder5.Items.Add
MyItem.Display
End Sub
 
S

Sue Mosher [MVP-Outlook]

MyItem.Links.Add(Item)

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

Mike

I receive an error ("Could not complete the operation. One or more
parameters are invalid.") when I insert the code you replied with.

MyItem.Links.Add(Item)

I am assuming that "Item" in parens needs to be replaced with a valid object
name - but which one? Do I place the field name that I am pulling from or
the destination location? Do they need to be named the same on both forms?

I would like to pass the value from the "FullName" field of the modified
Contact form to a "Contacts..." field setup on the new custom form the
command button is opening - Here is what I have:

Sub CommandButton1_Click()

Set olns = Item.Application.GetNameSpace("MAPI")
Set MyFolder1 = olns.Folders("Public Folders")
Set MyFolder2 = MyFolder1.Folders("All Public Folders")
Set MyFolder3 = MyFolder2.Folders("Shamrock")
Set MyFolder4 = MyFolder3.Folders("General")
Set MyFolder5 = MyFolder4.Folders("Customer Notes")
Set MyItem = MyFolder5.Items.Add
MyItem.Links.Add(FullName)
MyItem.Display
End Sub
 
S

Sue Mosher [MVP-Outlook]

If, as your message implied, Item *is* a valid object. The intrinsic Item object represents the item where the code is running. This contact item needs to be saved before you can add it as a link to some other item. Does your scenario include launching the other form before the contact is saved? If so, add an Item.Save statement before you invoke the Links collection.

When you step through the code with the script debugger, which particular statement triggers the error you cited?

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

Mike

Sue,

Thank you so much for all of your help! Here is section of code that
crashes in the script editor:

MyItem.Links.Add(FullName)
 
K

Ken Slovak - [MVP - Outlook]

Any Link you add must be a ContactItem. A string value will error. In the
Object Browser it lists the argument for Add as an Object.
 

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