Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Forms / April 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 21 Apr 2005 22:35 GMT
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!!!
Sue Mosher [MVP-Outlook] - 21 Apr 2005 22:51 GMT
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.

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

>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
[quoted text clipped - 16 lines]
> If anyone knows of any sample .oft that I could model after or any resources
> that I may have missed - please help!!!
Mike - 22 Apr 2005 15:59 GMT
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

> 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.
>
[quoted text clipped - 18 lines]
> > If anyone knows of any sample .oft that I could model after or any resources
> > that I may have missed - please help!!!
Sue Mosher [MVP-Outlook] - 22 Apr 2005 16:50 GMT
MyItem.Links.Add(Item)

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> 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
[quoted text clipped - 19 lines]
>
>> 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.

>> >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
[quoted text clipped - 16 lines]
>> > If anyone knows of any sample .oft that I could model after or any resources
>> > that I may have missed - please help!!!
Mike - 22 Apr 2005 21:13 GMT
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
   

> MyItem.Links.Add(Item)
>
[quoted text clipped - 42 lines]
> >> > If anyone knows of any sample .oft that I could model after or any resources
> >> > that I may have missed - please help!!!
Sue Mosher [MVP-Outlook] - 22 Apr 2005 22:22 GMT
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?

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

>I receive an error ("Could not complete the operation.  One or more
> parameters are invalid.") when I insert the code you replied with.  
[quoted text clipped - 24 lines]
>
>> MyItem.Links.Add(Item)

>> > 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
[quoted text clipped - 34 lines]
>> >> > "passes" it a parameter (in this case the Contact or Contacts) for the new
>> >> > form to be pre-populated.  
Mike - 25 Apr 2005 14:13 GMT
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)

> 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.
>
[quoted text clipped - 67 lines]
> >> >> > "passes" it a parameter (in this case the Contact or Contacts) for the new
> >> >> > form to be pre-populated.  
Ken Slovak - [MVP - Outlook] - 26 Apr 2005 14:28 GMT
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.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> 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)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.