How to change focus to added address card

B

Boein

Hi,
Using modified contact forms with vbs. After adding a contact from a
contact the focus is still set on the previous contact if you look at the
selected address cards. How can you set the focus on the added contact.
Thanks
Boein
 
S

Sue Mosher [MVP-Outlook]

You can't. Outlook provides no method for selecting a particular item in a folder view.
 
B

Boein

OK then what happens if you're running a form from a folder and you want to
add a new one from within this form. If I do this the same data is in the
new form and the first form. What am I doing wrong.
This is what I want.
A folder with a collection of custom forms (ie modified contact-items).
Each form contains vbs and has a combobox and contact fields. This combobox
contains all the forms in the folder. If I select an item from this combobox
the corresponding form should be openend showing corresponding data in the
fields. If I chage a value in one of the fields and press a save button the
corresponding form shown in the combobox should be updated. Sounds easy,
but is not ;-)
Regards
Boein
 
S

Sue Mosher [MVP-Outlook]

I'm confused over whether you mean "form" and "item" in your description of the contents of the combo box. A form is a code/UI template. It contains no data, although it may have default values for certain fields. An item is the unit of data storage. It is linked to a particular form through the value of its MessageClass property.

So are you talking about published custom forms? Or are you talking about creating new items from existing items (which may or may not be using a custom form)? Or something else completely?

To create a new item that uses a custom form for its UI and code, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

If it's a message form, 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. To create an item in another person's mailbox, use Namespace.GetSharedDefaultFolder to get the MAPIFolder 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.

To create a new item that is a copy of an existing item, call the Copy method on the item you want to copy:

Set newItem = oldItem.Copy

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
B

Boein

Hi Sue,

Form and item is exactly like you discribed. The combobox in the form
should be filled dynamicaly when the form is started the form should read a
field of all the other forms and add this field to the combobox. When the
loop is done the combobox is filled and you should be able to select and item
from it and this wil result in displaying the corresponding form.
 
B

Boein

I'm using almost the same code as you suggested. The item.copy I cannot use
because the problem occurs when adding a new item (item.add), so I cannot
start from an existing item because it's a new one.
 
B

Boein

Here's some code I use

sub save_click()

Set myItem = Application.ActiveInspector.CurrentItem

Set nms = Application.GetNameSpace("MAPI")
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
t_companyname=FormPage.Controls("companyname").value
t_BusinessAddressStreet= FormPage.Controls("BusinessAddressStreet").value
t_BusinessAddressCity= FormPage.Controls("BusinessAddressCity").value
t_BusinessAddressState= FormPage.Controls("BusinessAddressState").value
t_BusinessAddressPostalCode=
FormPage.Controls("BusinessAddressPostalCode").value
t_BusinessAddressCountry= FormPage.Controls("BusinessAddressCountry").value
t_BusinessTelephoneNumber=
FormPage.Controls("BusinessTelephoneNumber").value
t_BusinessFaxNumber= FormPage.Controls("BusinessFaxNumber").value
myitem.close 1

strFolder = "Structure"
fFound = FindFolder(nms.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders.Add(strFolder,
olFolderContacts)
End If
Set itms = fld.Items
set itm = itms.find("[companyname] = '" & t_companyname & "'")
if itm is nothing then

Set itm = itms.Add("IPM.Contact.structure")

with itm
.companyname = t_companyname
.BusinessAddressStreet= t_BusinessAddressStreet
.BusinessAddressCity= t_BusinessAddressCity .BusinessAddressState=
t_BusinessAddressState .BusinessAddressPostalCode=
t_BusinessAddressPostalCode .BusinessAddressCountry=
t_BusinessAddressCountry .BusinessTelephoneNumber=
t_BusinessTelephoneNumber .BusinessFaxNumber= t_BusinessFaxNumber

end with
itm.save
Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display
else

end if
call fill_combobox
end sub


function fill_combobox()
Set nms1 = Application.GetNameSpace("MAPI")
Set FormPage1 = Item.GetInspector.ModifiedFormPages("General")
Set Control1 = FormPage1.Controls("scompany")
FormPage1.controls("scompany").clear
strFolder = "Structure"
fFound = FindFolder(nms1.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld1 = nms1.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld1 = nms1.Folders("Mailbox -
PZ").folders("PZ").Folders.Add(strFolder, olFolderContacts)
End If
tel=0
Set itms1 = fld1.Items
numitems = itms1.count

numcontacts=0

ReDim FullArray(NumItems-1)

For I = 1 to numitems
set itm1 = itms1(i)
NumContacts = NumContacts + 1
FullArray(NumContacts-1) = itm1.companyname
Next
for i = UBound(FullArray) - 1 To 0 Step -1
for j= 0 to i
if FullArray(j)>FullArray(j+1) then
temp=FullArray(j+1)
FullArray(j+1)=FullArray(j)
FullArray(j)=temp
end if
next
next

control1.ColumnCount = 1

If NumItems = NumContacts Then
control1.List() = FullArray
Else

Dim ConArray()
ReDim ConArray(NumContacts-1,2)
For I = 0 to NumContacts - 1
ConArray(I,1) = FullArray(I)

Next
control1.List() = ConArray

End If
set nms1=nothing
set fld1=nothing
set formpage1=nothing
set control1=nothing
set itm1=nothing
set itms1=nothing
end function
 
S

Sue Mosher [MVP-Outlook]

So, what is the specific problem? And the related code? I still don't understand whether you are trying to create (a) new items that are copies of existing items or (b) new, blank items using a published custom form. Which is it?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
S

Sue Mosher [MVP-Outlook]

With that code, you're creating an item in the Structure folder using the IPM.Contact.structure form and then setting some values for the new item that you got from the old item. (You got them the hard way -- reading control values when you should have been reading property values.)

This section has the statements out of order:

Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display

Since you closed the original item, there may be no ActiveInspector at all, much less an Inspector for the newly created item. Instead, display the item first, then set its current form page. However, unless you've done a heavy redesign and renamed pages, there is no need to set the "General" page as current. The first page is always the one displayed by default.

The code then fills a combo box on the item with the names of companies in the Structure folder, but I'm not sure I understand the use of two arrays.

What specific problem are you encountering?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Boein said:
Here's some code I use

sub save_click()

Set myItem = Application.ActiveInspector.CurrentItem

Set nms = Application.GetNameSpace("MAPI")
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
t_companyname=FormPage.Controls("companyname").value
t_BusinessAddressStreet= FormPage.Controls("BusinessAddressStreet").value
t_BusinessAddressCity= FormPage.Controls("BusinessAddressCity").value
t_BusinessAddressState= FormPage.Controls("BusinessAddressState").value
t_BusinessAddressPostalCode=
FormPage.Controls("BusinessAddressPostalCode").value
t_BusinessAddressCountry= FormPage.Controls("BusinessAddressCountry").value
t_BusinessTelephoneNumber=
FormPage.Controls("BusinessTelephoneNumber").value
t_BusinessFaxNumber= FormPage.Controls("BusinessFaxNumber").value
myitem.close 1

strFolder = "Structure"
fFound = FindFolder(nms.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders.Add(strFolder,
olFolderContacts)
End If
Set itms = fld.Items
set itm = itms.find("[companyname] = '" & t_companyname & "'")
if itm is nothing then

Set itm = itms.Add("IPM.Contact.structure")

with itm
.companyname = t_companyname
.BusinessAddressStreet= t_BusinessAddressStreet
.BusinessAddressCity= t_BusinessAddressCity .BusinessAddressState=
t_BusinessAddressState .BusinessAddressPostalCode=
t_BusinessAddressPostalCode .BusinessAddressCountry=
t_BusinessAddressCountry .BusinessTelephoneNumber=
t_BusinessTelephoneNumber .BusinessFaxNumber= t_BusinessFaxNumber

end with
itm.save
Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display
else

end if
call fill_combobox
end sub


function fill_combobox()
Set nms1 = Application.GetNameSpace("MAPI")
Set FormPage1 = Item.GetInspector.ModifiedFormPages("General")
Set Control1 = FormPage1.Controls("scompany")
FormPage1.controls("scompany").clear
strFolder = "Structure"
fFound = FindFolder(nms1.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld1 = nms1.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld1 = nms1.Folders("Mailbox -
PZ").folders("PZ").Folders.Add(strFolder, olFolderContacts)
End If
tel=0
Set itms1 = fld1.Items
numitems = itms1.count

numcontacts=0

ReDim FullArray(NumItems-1)

For I = 1 to numitems
set itm1 = itms1(i)
NumContacts = NumContacts + 1
FullArray(NumContacts-1) = itm1.companyname
Next
for i = UBound(FullArray) - 1 To 0 Step -1
for j= 0 to i
if FullArray(j)>FullArray(j+1) then
temp=FullArray(j+1)
FullArray(j+1)=FullArray(j)
FullArray(j)=temp
end if
next
next

control1.ColumnCount = 1

If NumItems = NumContacts Then
control1.List() = FullArray
Else

Dim ConArray()
ReDim ConArray(NumContacts-1,2)
For I = 0 to NumContacts - 1
ConArray(I,1) = FullArray(I)

Next
control1.List() = ConArray

End If
set nms1=nothing
set fld1=nothing
set formpage1=nothing
set control1=nothing
set itm1=nothing
set itms1=nothing
end function




Sue Mosher said:
Did you try the code I suggested for creating a new item using a custom form?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
B

Boein

Ok you did some nice reverse engineering ;-) If I run the program like this
it works, when press "save" an item it's created and it appears between the
others in de structure folder. But I have a problem with the combobox. The
value of the new created item occurs in the combobox, but the previous item
is also replaced. With previous I mean: the value from the last open item.
Also If i select an item from the combobox it opens the right corresponding
item but if a create a new one, again the new item is added to the combobox
but the previous item in the combobox is again replaced... If I do it again,
the item in the combobox that was wrong is corrected but again the last one
is added and de previous one is wrong...and so on.
The arrays in the program is to order the contents in the combobox.



Sue Mosher said:
With that code, you're creating an item in the Structure folder using the IPM.Contact.structure form and then setting some values for the new item that you got from the old item. (You got them the hard way -- reading control values when you should have been reading property values.)

This section has the statements out of order:

Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display

Since you closed the original item, there may be no ActiveInspector at all, much less an Inspector for the newly created item. Instead, display the item first, then set its current form page. However, unless you've done a heavy redesign and renamed pages, there is no need to set the "General" page as current. The first page is always the one displayed by default.

The code then fills a combo box on the item with the names of companies in the Structure folder, but I'm not sure I understand the use of two arrays.

What specific problem are you encountering?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Boein said:
Here's some code I use

sub save_click()

Set myItem = Application.ActiveInspector.CurrentItem

Set nms = Application.GetNameSpace("MAPI")
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
t_companyname=FormPage.Controls("companyname").value
t_BusinessAddressStreet= FormPage.Controls("BusinessAddressStreet").value
t_BusinessAddressCity= FormPage.Controls("BusinessAddressCity").value
t_BusinessAddressState= FormPage.Controls("BusinessAddressState").value
t_BusinessAddressPostalCode=
FormPage.Controls("BusinessAddressPostalCode").value
t_BusinessAddressCountry= FormPage.Controls("BusinessAddressCountry").value
t_BusinessTelephoneNumber=
FormPage.Controls("BusinessTelephoneNumber").value
t_BusinessFaxNumber= FormPage.Controls("BusinessFaxNumber").value
myitem.close 1

strFolder = "Structure"
fFound = FindFolder(nms.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders.Add(strFolder,
olFolderContacts)
End If
Set itms = fld.Items
set itm = itms.find("[companyname] = '" & t_companyname & "'")
if itm is nothing then

Set itm = itms.Add("IPM.Contact.structure")

with itm
.companyname = t_companyname
.BusinessAddressStreet= t_BusinessAddressStreet
.BusinessAddressCity= t_BusinessAddressCity .BusinessAddressState=
t_BusinessAddressState .BusinessAddressPostalCode=
t_BusinessAddressPostalCode .BusinessAddressCountry=
t_BusinessAddressCountry .BusinessTelephoneNumber=
t_BusinessTelephoneNumber .BusinessFaxNumber= t_BusinessFaxNumber

end with
itm.save
Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display
else

end if
call fill_combobox
end sub


function fill_combobox()
Set nms1 = Application.GetNameSpace("MAPI")
Set FormPage1 = Item.GetInspector.ModifiedFormPages("General")
Set Control1 = FormPage1.Controls("scompany")
FormPage1.controls("scompany").clear
strFolder = "Structure"
fFound = FindFolder(nms1.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld1 = nms1.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld1 = nms1.Folders("Mailbox -
PZ").folders("PZ").Folders.Add(strFolder, olFolderContacts)
End If
tel=0
Set itms1 = fld1.Items
numitems = itms1.count

numcontacts=0

ReDim FullArray(NumItems-1)

For I = 1 to numitems
set itm1 = itms1(i)
NumContacts = NumContacts + 1
FullArray(NumContacts-1) = itm1.companyname
Next
for i = UBound(FullArray) - 1 To 0 Step -1
for j= 0 to i
if FullArray(j)>FullArray(j+1) then
temp=FullArray(j+1)
FullArray(j+1)=FullArray(j)
FullArray(j)=temp
end if
next
next

control1.ColumnCount = 1

If NumItems = NumContacts Then
control1.List() = FullArray
Else

Dim ConArray()
ReDim ConArray(NumContacts-1,2)
For I = 0 to NumContacts - 1
ConArray(I,1) = FullArray(I)

Next
control1.List() = ConArray

End If
set nms1=nothing
set fld1=nothing
set formpage1=nothing
set control1=nothing
set itm1=nothing
set itms1=nothing
end function




Sue Mosher said:
Did you try the code I suggested for creating a new item using a custom form?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Hi Sue,

Form and item is exactly like you discribed. The combobox in the form
should be filled dynamicaly when the form is started the form should read a
field of all the other forms and add this field to the combobox. When the
loop is done the combobox is filled and you should be able to select and item
from it and this wil result in displaying the corresponding form.

:

I'm confused over whether you mean "form" and "item" in your description of the contents of the combo box. A form is a code/UI template. It contains no data, although it may have default values for certain fields. An item is the unit of data storage. It is linked to a particular form through the value of its MessageClass property.

So are you talking about published custom forms? Or are you talking about creating new items from existing items (which may or may not be using a custom form)? Or something else completely?

To create a new item that uses a custom form for its UI and code, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

If it's a message form, 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. To create an item in another person's mailbox, use Namespace.GetSharedDefaultFolder to get the MAPIFolder 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.

To create a new item that is a copy of an existing item, call the Copy method on the item you want to copy:

Set newItem = oldItem.Copy


OK then what happens if you're running a form from a folder and you want to
add a new one from within this form. If I do this the same data is in the
new form and the first form. What am I doing wrong.
This is what I want.
A folder with a collection of custom forms (ie modified contact-items).
Each form contains vbs and has a combobox and contact fields. This combobox
contains all the forms in the folder. If I select an item from this combobox
the corresponding form should be openend showing corresponding data in the
fields. If I chage a value in one of the fields and press a save button the
corresponding form shown in the combobox should be updated. Sounds easy,
but is not ;-)
Regards
Boein


:

You can't. Outlook provides no method for selecting a particular item in a folder view.

Hi,
Using modified contact forms with vbs. After adding a contact from a
contact the focus is still set on the previous contact if you look at the
selected address cards. How can you set the focus on the added contact.
Thanks
Boein
 
S

Sue Mosher [MVP-Outlook]

An easier way to sort the contents for the combo box would be to return the Items collection from the folder and then call its Sort method *before* you iterate the Items collection. Maybe just simplifying the way you load the rows would solve the problem.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Boein said:
Ok you did some nice reverse engineering ;-) If I run the program like this
it works, when press "save" an item it's created and it appears between the
others in de structure folder. But I have a problem with the combobox. The
value of the new created item occurs in the combobox, but the previous item
is also replaced. With previous I mean: the value from the last open item.
Also If i select an item from the combobox it opens the right corresponding
item but if a create a new one, again the new item is added to the combobox
but the previous item in the combobox is again replaced... If I do it again,
the item in the combobox that was wrong is corrected but again the last one
is added and de previous one is wrong...and so on.
The arrays in the program is to order the contents in the combobox.



Sue Mosher said:
With that code, you're creating an item in the Structure folder using the IPM.Contact.structure form and then setting some values for the new item that you got from the old item. (You got them the hard way -- reading control values when you should have been reading property values.)

This section has the statements out of order:

Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display

Since you closed the original item, there may be no ActiveInspector at all, much less an Inspector for the newly created item. Instead, display the item first, then set its current form page. However, unless you've done a heavy redesign and renamed pages, there is no need to set the "General" page as current. The first page is always the one displayed by default.

The code then fills a combo box on the item with the names of companies in the Structure folder, but I'm not sure I understand the use of two arrays.

What specific problem are you encountering?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Boein said:
Here's some code I use

sub save_click()

Set myItem = Application.ActiveInspector.CurrentItem

Set nms = Application.GetNameSpace("MAPI")
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
t_companyname=FormPage.Controls("companyname").value
t_BusinessAddressStreet= FormPage.Controls("BusinessAddressStreet").value
t_BusinessAddressCity= FormPage.Controls("BusinessAddressCity").value
t_BusinessAddressState= FormPage.Controls("BusinessAddressState").value
t_BusinessAddressPostalCode=
FormPage.Controls("BusinessAddressPostalCode").value
t_BusinessAddressCountry= FormPage.Controls("BusinessAddressCountry").value
t_BusinessTelephoneNumber=
FormPage.Controls("BusinessTelephoneNumber").value
t_BusinessFaxNumber= FormPage.Controls("BusinessFaxNumber").value
myitem.close 1

strFolder = "Structure"
fFound = FindFolder(nms.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders.Add(strFolder,
olFolderContacts)
End If
Set itms = fld.Items
set itm = itms.find("[companyname] = '" & t_companyname & "'")
if itm is nothing then

Set itm = itms.Add("IPM.Contact.structure")

with itm
.companyname = t_companyname
.BusinessAddressStreet= t_BusinessAddressStreet
.BusinessAddressCity= t_BusinessAddressCity ..BusinessAddressState=
t_BusinessAddressState .BusinessAddressPostalCode=
t_BusinessAddressPostalCode .BusinessAddressCountry=
t_BusinessAddressCountry .BusinessTelephoneNumber=
t_BusinessTelephoneNumber .BusinessFaxNumber= t_BusinessFaxNumber

end with
itm.save
Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display
else

end if
call fill_combobox
end sub


function fill_combobox()
Set nms1 = Application.GetNameSpace("MAPI")
Set FormPage1 = Item.GetInspector.ModifiedFormPages("General")
Set Control1 = FormPage1.Controls("scompany")
FormPage1.controls("scompany").clear
strFolder = "Structure"
fFound = FindFolder(nms1.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld1 = nms1.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld1 = nms1.Folders("Mailbox -
PZ").folders("PZ").Folders.Add(strFolder, olFolderContacts)
End If
tel=0
Set itms1 = fld1.Items
numitems = itms1.count

numcontacts=0

ReDim FullArray(NumItems-1)

For I = 1 to numitems
set itm1 = itms1(i)
NumContacts = NumContacts + 1
FullArray(NumContacts-1) = itm1.companyname
Next
for i = UBound(FullArray) - 1 To 0 Step -1
for j= 0 to i
if FullArray(j)>FullArray(j+1) then
temp=FullArray(j+1)
FullArray(j+1)=FullArray(j)
FullArray(j)=temp
end if
next
next

control1.ColumnCount = 1

If NumItems = NumContacts Then
control1.List() = FullArray
Else

Dim ConArray()
ReDim ConArray(NumContacts-1,2)
For I = 0 to NumContacts - 1
ConArray(I,1) = FullArray(I)

Next
control1.List() = ConArray

End If
set nms1=nothing
set fld1=nothing
set formpage1=nothing
set control1=nothing
set itm1=nothing
set itms1=nothing
end function




:

Did you try the code I suggested for creating a new item using a custom form?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Hi Sue,

Form and item is exactly like you discribed. The combobox in the form
should be filled dynamicaly when the form is started the form should read a
field of all the other forms and add this field to the combobox. When the
loop is done the combobox is filled and you should be able to select and item
from it and this wil result in displaying the corresponding form.

:

I'm confused over whether you mean "form" and "item" in your description of the contents of the combo box. A form is a code/UI template. It contains no data, although it may have default values for certain fields. An item is the unit of data storage. It is linked to a particular form through the value of its MessageClass property.

So are you talking about published custom forms? Or are you talking about creating new items from existing items (which may or may not be using a custom form)? Or something else completely?

To create a new item that uses a custom form for its UI and code, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

If it's a message form, 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. To create an item in another person's mailbox, use Namespace.GetSharedDefaultFolder to get the MAPIFolder 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.

To create a new item that is a copy of an existing item, call the Copy method on the item you want to copy:

Set newItem = oldItem.Copy


OK then what happens if you're running a form from a folder and you want to
add a new one from within this form. If I do this the same data is in the
new form and the first form. What am I doing wrong.
This is what I want.
A folder with a collection of custom forms (ie modified contact-items).
Each form contains vbs and has a combobox and contact fields. This combobox
contains all the forms in the folder. If I select an item from this combobox
the corresponding form should be openend showing corresponding data in the
fields. If I chage a value in one of the fields and press a save button the
corresponding form shown in the combobox should be updated. Sounds easy,
but is not ;-)
Regards
Boein


:

You can't. Outlook provides no method for selecting a particular item in a folder view.

Hi,
Using modified contact forms with vbs. After adding a contact from a
contact the focus is still set on the previous contact if you look at the
selected address cards. How can you set the focus on the added contact.
Thanks
Boein
 
B

Boein

Hi Sue,
I dug a little deeper and for some reason the value you want to add is saved
2 times. One time when calling the add-method and the second time I guess
when changing value on the item I started from (to make a next item). Maybe
the second item made from the first one inherits some values. I just don't
understand it. Next problem. The combobox (scompany) is an unbound control.
To fill it I need to refer to it by using these commands:
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
Set Control = FormPage.Controls("scompany")
how can I be sure that i'm referring to the item i'm working with (the item
that has focus). If I create a new item (add method) followed by a display
and then using these commands result in an error "you don't have the
appropriate permission to perform this operation).


Sue Mosher said:
An easier way to sort the contents for the combo box would be to return the Items collection from the folder and then call its Sort method *before* you iterate the Items collection. Maybe just simplifying the way you load the rows would solve the problem.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Boein said:
Ok you did some nice reverse engineering ;-) If I run the program like this
it works, when press "save" an item it's created and it appears between the
others in de structure folder. But I have a problem with the combobox. The
value of the new created item occurs in the combobox, but the previous item
is also replaced. With previous I mean: the value from the last open item.
Also If i select an item from the combobox it opens the right corresponding
item but if a create a new one, again the new item is added to the combobox
but the previous item in the combobox is again replaced... If I do it again,
the item in the combobox that was wrong is corrected but again the last one
is added and de previous one is wrong...and so on.
The arrays in the program is to order the contents in the combobox.



Sue Mosher said:
With that code, you're creating an item in the Structure folder using the IPM.Contact.structure form and then setting some values for the new item that you got from the old item. (You got them the hard way -- reading control values when you should have been reading property values.)

This section has the statements out of order:

Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display

Since you closed the original item, there may be no ActiveInspector at all, much less an Inspector for the newly created item. Instead, display the item first, then set its current form page. However, unless you've done a heavy redesign and renamed pages, there is no need to set the "General" page as current. The first page is always the one displayed by default.

The code then fills a combo box on the item with the names of companies in the Structure folder, but I'm not sure I understand the use of two arrays.

What specific problem are you encountering?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Here's some code I use

sub save_click()

Set myItem = Application.ActiveInspector.CurrentItem

Set nms = Application.GetNameSpace("MAPI")
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
t_companyname=FormPage.Controls("companyname").value
t_BusinessAddressStreet= FormPage.Controls("BusinessAddressStreet").value
t_BusinessAddressCity= FormPage.Controls("BusinessAddressCity").value
t_BusinessAddressState= FormPage.Controls("BusinessAddressState").value
t_BusinessAddressPostalCode=
FormPage.Controls("BusinessAddressPostalCode").value
t_BusinessAddressCountry= FormPage.Controls("BusinessAddressCountry").value
t_BusinessTelephoneNumber=
FormPage.Controls("BusinessTelephoneNumber").value
t_BusinessFaxNumber= FormPage.Controls("BusinessFaxNumber").value
myitem.close 1

strFolder = "Structure"
fFound = FindFolder(nms.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders.Add(strFolder,
olFolderContacts)
End If
Set itms = fld.Items
set itm = itms.find("[companyname] = '" & t_companyname & "'")
if itm is nothing then

Set itm = itms.Add("IPM.Contact.structure")

with itm
.companyname = t_companyname
.BusinessAddressStreet= t_BusinessAddressStreet
.BusinessAddressCity= t_BusinessAddressCity ..BusinessAddressState=
t_BusinessAddressState .BusinessAddressPostalCode=
t_BusinessAddressPostalCode .BusinessAddressCountry=
t_BusinessAddressCountry .BusinessTelephoneNumber=
t_BusinessTelephoneNumber .BusinessFaxNumber= t_BusinessFaxNumber

end with
itm.save
Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display
else

end if
call fill_combobox
end sub


function fill_combobox()
Set nms1 = Application.GetNameSpace("MAPI")
Set FormPage1 = Item.GetInspector.ModifiedFormPages("General")
Set Control1 = FormPage1.Controls("scompany")
FormPage1.controls("scompany").clear
strFolder = "Structure"
fFound = FindFolder(nms1.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld1 = nms1.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld1 = nms1.Folders("Mailbox -
PZ").folders("PZ").Folders.Add(strFolder, olFolderContacts)
End If
tel=0
Set itms1 = fld1.Items
numitems = itms1.count

numcontacts=0

ReDim FullArray(NumItems-1)

For I = 1 to numitems
set itm1 = itms1(i)
NumContacts = NumContacts + 1
FullArray(NumContacts-1) = itm1.companyname
Next
for i = UBound(FullArray) - 1 To 0 Step -1
for j= 0 to i
if FullArray(j)>FullArray(j+1) then
temp=FullArray(j+1)
FullArray(j+1)=FullArray(j)
FullArray(j)=temp
end if
next
next

control1.ColumnCount = 1

If NumItems = NumContacts Then
control1.List() = FullArray
Else

Dim ConArray()
ReDim ConArray(NumContacts-1,2)
For I = 0 to NumContacts - 1
ConArray(I,1) = FullArray(I)

Next
control1.List() = ConArray

End If
set nms1=nothing
set fld1=nothing
set formpage1=nothing
set control1=nothing
set itm1=nothing
set itms1=nothing
end function




:

Did you try the code I suggested for creating a new item using a custom form?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Hi Sue,

Form and item is exactly like you discribed. The combobox in the form
should be filled dynamicaly when the form is started the form should read a
field of all the other forms and add this field to the combobox. When the
loop is done the combobox is filled and you should be able to select and item
from it and this wil result in displaying the corresponding form.

:

I'm confused over whether you mean "form" and "item" in your description of the contents of the combo box. A form is a code/UI template. It contains no data, although it may have default values for certain fields. An item is the unit of data storage. It is linked to a particular form through the value of its MessageClass property.

So are you talking about published custom forms? Or are you talking about creating new items from existing items (which may or may not be using a custom form)? Or something else completely?

To create a new item that uses a custom form for its UI and code, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

If it's a message form, 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. To create an item in another person's mailbox, use Namespace.GetSharedDefaultFolder to get the MAPIFolder 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.

To create a new item that is a copy of an existing item, call the Copy method on the item you want to copy:

Set newItem = oldItem.Copy


OK then what happens if you're running a form from a folder and you want to
add a new one from within this form. If I do this the same data is in the
new form and the first form. What am I doing wrong.
This is what I want.
A folder with a collection of custom forms (ie modified contact-items).
Each form contains vbs and has a combobox and contact fields. This combobox
contains all the forms in the folder. If I select an item from this combobox
the corresponding form should be openend showing corresponding data in the
fields. If I chage a value in one of the fields and press a save button the
corresponding form shown in the combobox should be updated. Sounds easy,
but is not ;-)
Regards
Boein


:

You can't. Outlook provides no method for selecting a particular item in a folder view.

Hi,
Using modified contact forms with vbs. After adding a contact from a
contact the focus is still set on the previous contact if you look at the
selected address cards. How can you set the focus on the added contact.
Thanks
Boein
 
S

Sue Mosher [MVP-Outlook]

I'm not sure what value or values you're referring to as "value you want to add." Could you be more specific?

In code behind an Outlook form, the intrinsic Item object always refers to the current item whose form's code is running. If you create a new item and want to work with its controls, you use the same GetInspector method as you use on Item to return the Inspector for the new item:

Set itm = itms.Add("IPM.Contact.structure")
Set insp = itm.GetInspector

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Boein said:
Hi Sue,
I dug a little deeper and for some reason the value you want to add is saved
2 times. One time when calling the add-method and the second time I guess
when changing value on the item I started from (to make a next item). Maybe
the second item made from the first one inherits some values. I just don't
understand it. Next problem. The combobox (scompany) is an unbound control.
To fill it I need to refer to it by using these commands:
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
Set Control = FormPage.Controls("scompany")
how can I be sure that i'm referring to the item i'm working with (the item
that has focus). If I create a new item (add method) followed by a display
and then using these commands result in an error "you don't have the
appropriate permission to perform this operation).


Sue Mosher said:
An easier way to sort the contents for the combo box would be to return the Items collection from the folder and then call its Sort method *before* you iterate the Items collection. Maybe just simplifying the way you load the rows would solve the problem.

Boein said:
Ok you did some nice reverse engineering ;-) If I run the program like this
it works, when press "save" an item it's created and it appears between the
others in de structure folder. But I have a problem with the combobox. The
value of the new created item occurs in the combobox, but the previous item
is also replaced. With previous I mean: the value from the last open item.
Also If i select an item from the combobox it opens the right corresponding
item but if a create a new one, again the new item is added to the combobox
but the previous item in the combobox is again replaced... If I do it again,
the item in the combobox that was wrong is corrected but again the last one
is added and de previous one is wrong...and so on.
The arrays in the program is to order the contents in the combobox.



:

With that code, you're creating an item in the Structure folder using the IPM.Contact.structure form and then setting some values for the new item that you got from the old item. (You got them the hard way -- reading control values when you should have been reading property values.)

This section has the statements out of order:

Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display

Since you closed the original item, there may be no ActiveInspector at all, much less an Inspector for the newly created item. Instead, display the item first, then set its current form page. However, unless you've done a heavy redesign and renamed pages, there is no need to set the "General" page as current. The first page is always the one displayed by default.

The code then fills a combo box on the item with the names of companies in the Structure folder, but I'm not sure I understand the use of two arrays.

What specific problem are you encountering?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Here's some code I use

sub save_click()

Set myItem = Application.ActiveInspector.CurrentItem

Set nms = Application.GetNameSpace("MAPI")
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
t_companyname=FormPage.Controls("companyname").value
t_BusinessAddressStreet= FormPage.Controls("BusinessAddressStreet").value
t_BusinessAddressCity= FormPage.Controls("BusinessAddressCity").value
t_BusinessAddressState= FormPage.Controls("BusinessAddressState").value
t_BusinessAddressPostalCode=
FormPage.Controls("BusinessAddressPostalCode").value
t_BusinessAddressCountry= FormPage.Controls("BusinessAddressCountry").value
t_BusinessTelephoneNumber=
FormPage.Controls("BusinessTelephoneNumber").value
t_BusinessFaxNumber= FormPage.Controls("BusinessFaxNumber").value
myitem.close 1

strFolder = "Structure"
fFound = FindFolder(nms.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders.Add(strFolder,
olFolderContacts)
End If
Set itms = fld.Items
set itm = itms.find("[companyname] = '" & t_companyname & "'")
if itm is nothing then

Set itm = itms.Add("IPM.Contact.structure")

with itm
.companyname = t_companyname
.BusinessAddressStreet= t_BusinessAddressStreet
.BusinessAddressCity= t_BusinessAddressCity ...BusinessAddressState=
t_BusinessAddressState .BusinessAddressPostalCode=
t_BusinessAddressPostalCode .BusinessAddressCountry=
t_BusinessAddressCountry .BusinessTelephoneNumber=
t_BusinessTelephoneNumber .BusinessFaxNumber= t_BusinessFaxNumber

end with
itm.save
Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display
else

end if
call fill_combobox
end sub


function fill_combobox()
Set nms1 = Application.GetNameSpace("MAPI")
Set FormPage1 = Item.GetInspector.ModifiedFormPages("General")
Set Control1 = FormPage1.Controls("scompany")
FormPage1.controls("scompany").clear
strFolder = "Structure"
fFound = FindFolder(nms1.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld1 = nms1.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld1 = nms1.Folders("Mailbox -
PZ").folders("PZ").Folders.Add(strFolder, olFolderContacts)
End If
tel=0
Set itms1 = fld1.Items
numitems = itms1.count

numcontacts=0

ReDim FullArray(NumItems-1)

For I = 1 to numitems
set itm1 = itms1(i)
NumContacts = NumContacts + 1
FullArray(NumContacts-1) = itm1.companyname
Next
for i = UBound(FullArray) - 1 To 0 Step -1
for j= 0 to i
if FullArray(j)>FullArray(j+1) then
temp=FullArray(j+1)
FullArray(j+1)=FullArray(j)
FullArray(j)=temp
end if
next
next

control1.ColumnCount = 1

If NumItems = NumContacts Then
control1.List() = FullArray
Else

Dim ConArray()
ReDim ConArray(NumContacts-1,2)
For I = 0 to NumContacts - 1
ConArray(I,1) = FullArray(I)

Next
control1.List() = ConArray

End If
set nms1=nothing
set fld1=nothing
set formpage1=nothing
set control1=nothing
set itm1=nothing
set itms1=nothing
end function




:

Did you try the code I suggested for creating a new item using a custom form?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Hi Sue,

Form and item is exactly like you discribed. The combobox in the form
should be filled dynamicaly when the form is started the form should read a
field of all the other forms and add this field to the combobox. When the
loop is done the combobox is filled and you should be able to select and item
from it and this wil result in displaying the corresponding form.

:

I'm confused over whether you mean "form" and "item" in your description of the contents of the combo box. A form is a code/UI template. It contains no data, although it may have default values for certain fields. An item is the unit of data storage. It is linked to a particular form through the value of its MessageClass property.

So are you talking about published custom forms? Or are you talking about creating new items from existing items (which may or may not be using a custom form)? Or something else completely?

To create a new item that uses a custom form for its UI and code, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

If it's a message form, 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. To create an item in another person's mailbox, use Namespace.GetSharedDefaultFolder to get the MAPIFolder 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.

To create a new item that is a copy of an existing item, call the Copy method on the item you want to copy:

Set newItem = oldItem.Copy


OK then what happens if you're running a form from a folder and you want to
add a new one from within this form. If I do this the same data is in the
new form and the first form. What am I doing wrong.
This is what I want.
A folder with a collection of custom forms (ie modified contact-items).
Each form contains vbs and has a combobox and contact fields. This combobox
contains all the forms in the folder. If I select an item from this combobox
the corresponding form should be openend showing corresponding data in the
fields. If I chage a value in one of the fields and press a save button the
corresponding form shown in the combobox should be updated. Sounds easy,
but is not ;-)
Regards
Boein


:

You can't. Outlook provides no method for selecting a particular item in a folder view.

Hi,
Using modified contact forms with vbs. After adding a contact from a
contact the focus is still set on the previous contact if you look at the
selected address cards. How can you set the focus on the added contact.
Thanks
Boein
 
B

Boein

Hi Sue,
sorry for the delay. The value I want to add is the company in a text-box.
Let me explain one more time how it should work.
A custom form has 1 txt-field (bound) and 1 combobox (unbound) and a save
button. If you fill in the txt-field and press on the save button, the value
of the txt-field should be added to the combobox. Before doing this, a
script behind the save button checks if the value in the txt-box corresponds
to an existing outlook-item which has the same value in its txt-field , if it
does, the contents in the item can be updated, if it does not a new item is
created and the txt-field is added to the combobox
To view an item, klick on the combobox select an item in it an this item
will be displayed. Maybe you can provide me some code to start because it
really won't work.

regards
Boein



Sue Mosher said:
I'm not sure what value or values you're referring to as "value you want to add." Could you be more specific?

In code behind an Outlook form, the intrinsic Item object always refers to the current item whose form's code is running. If you create a new item and want to work with its controls, you use the same GetInspector method as you use on Item to return the Inspector for the new item:

Set itm = itms.Add("IPM.Contact.structure")
Set insp = itm.GetInspector

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Boein said:
Hi Sue,
I dug a little deeper and for some reason the value you want to add is saved
2 times. One time when calling the add-method and the second time I guess
when changing value on the item I started from (to make a next item). Maybe
the second item made from the first one inherits some values. I just don't
understand it. Next problem. The combobox (scompany) is an unbound control.
To fill it I need to refer to it by using these commands:
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
Set Control = FormPage.Controls("scompany")
how can I be sure that i'm referring to the item i'm working with (the item
that has focus). If I create a new item (add method) followed by a display
and then using these commands result in an error "you don't have the
appropriate permission to perform this operation).


Sue Mosher said:
An easier way to sort the contents for the combo box would be to return the Items collection from the folder and then call its Sort method *before* you iterate the Items collection. Maybe just simplifying the way you load the rows would solve the problem.

Ok you did some nice reverse engineering ;-) If I run the program like this
it works, when press "save" an item it's created and it appears between the
others in de structure folder. But I have a problem with the combobox. The
value of the new created item occurs in the combobox, but the previous item
is also replaced. With previous I mean: the value from the last open item.
Also If i select an item from the combobox it opens the right corresponding
item but if a create a new one, again the new item is added to the combobox
but the previous item in the combobox is again replaced... If I do it again,
the item in the combobox that was wrong is corrected but again the last one
is added and de previous one is wrong...and so on.
The arrays in the program is to order the contents in the combobox.



:

With that code, you're creating an item in the Structure folder using the IPM.Contact.structure form and then setting some values for the new item that you got from the old item. (You got them the hard way -- reading control values when you should have been reading property values.)

This section has the statements out of order:

Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display

Since you closed the original item, there may be no ActiveInspector at all, much less an Inspector for the newly created item. Instead, display the item first, then set its current form page. However, unless you've done a heavy redesign and renamed pages, there is no need to set the "General" page as current. The first page is always the one displayed by default.

The code then fills a combo box on the item with the names of companies in the Structure folder, but I'm not sure I understand the use of two arrays.

What specific problem are you encountering?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Here's some code I use

sub save_click()

Set myItem = Application.ActiveInspector.CurrentItem

Set nms = Application.GetNameSpace("MAPI")
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
t_companyname=FormPage.Controls("companyname").value
t_BusinessAddressStreet= FormPage.Controls("BusinessAddressStreet").value
t_BusinessAddressCity= FormPage.Controls("BusinessAddressCity").value
t_BusinessAddressState= FormPage.Controls("BusinessAddressState").value
t_BusinessAddressPostalCode=
FormPage.Controls("BusinessAddressPostalCode").value
t_BusinessAddressCountry= FormPage.Controls("BusinessAddressCountry").value
t_BusinessTelephoneNumber=
FormPage.Controls("BusinessTelephoneNumber").value
t_BusinessFaxNumber= FormPage.Controls("BusinessFaxNumber").value
myitem.close 1

strFolder = "Structure"
fFound = FindFolder(nms.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders.Add(strFolder,
olFolderContacts)
End If
Set itms = fld.Items
set itm = itms.find("[companyname] = '" & t_companyname & "'")
if itm is nothing then

Set itm = itms.Add("IPM.Contact.structure")

with itm
.companyname = t_companyname
.BusinessAddressStreet= t_BusinessAddressStreet
.BusinessAddressCity= t_BusinessAddressCity ...BusinessAddressState=
t_BusinessAddressState .BusinessAddressPostalCode=
t_BusinessAddressPostalCode .BusinessAddressCountry=
t_BusinessAddressCountry .BusinessTelephoneNumber=
t_BusinessTelephoneNumber .BusinessFaxNumber= t_BusinessFaxNumber

end with
itm.save
Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display
else

end if
call fill_combobox
end sub


function fill_combobox()
Set nms1 = Application.GetNameSpace("MAPI")
Set FormPage1 = Item.GetInspector.ModifiedFormPages("General")
Set Control1 = FormPage1.Controls("scompany")
FormPage1.controls("scompany").clear
strFolder = "Structure"
fFound = FindFolder(nms1.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld1 = nms1.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld1 = nms1.Folders("Mailbox -
PZ").folders("PZ").Folders.Add(strFolder, olFolderContacts)
End If
tel=0
Set itms1 = fld1.Items
numitems = itms1.count

numcontacts=0

ReDim FullArray(NumItems-1)

For I = 1 to numitems
set itm1 = itms1(i)
NumContacts = NumContacts + 1
FullArray(NumContacts-1) = itm1.companyname
Next
for i = UBound(FullArray) - 1 To 0 Step -1
for j= 0 to i
if FullArray(j)>FullArray(j+1) then
temp=FullArray(j+1)
FullArray(j+1)=FullArray(j)
FullArray(j)=temp
end if
next
next

control1.ColumnCount = 1

If NumItems = NumContacts Then
control1.List() = FullArray
Else

Dim ConArray()
ReDim ConArray(NumContacts-1,2)
For I = 0 to NumContacts - 1
ConArray(I,1) = FullArray(I)

Next
control1.List() = ConArray

End If
set nms1=nothing
set fld1=nothing
set formpage1=nothing
set control1=nothing
set itm1=nothing
set itms1=nothing
end function




:

Did you try the code I suggested for creating a new item using a custom form?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Hi Sue,

Form and item is exactly like you discribed. The combobox in the form
should be filled dynamicaly when the form is started the form should read a
field of all the other forms and add this field to the combobox. When the
loop is done the combobox is filled and you should be able to select and item
from it and this wil result in displaying the corresponding form.

:

I'm confused over whether you mean "form" and "item" in your description of the contents of the combo box. A form is a code/UI template. It contains no data, although it may have default values for certain fields. An item is the unit of data storage. It is linked to a particular form through the value of its MessageClass property.

So are you talking about published custom forms? Or are you talking about creating new items from existing items (which may or may not be using a custom form)? Or something else completely?

To create a new item that uses a custom form for its UI and code, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

If it's a message form, 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. To create an item in another person's mailbox, use Namespace.GetSharedDefaultFolder to get the MAPIFolder 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.

To create a new item that is a copy of an existing item, call the Copy method on the item you want to copy:

Set newItem = oldItem.Copy


OK then what happens if you're running a form from a folder and you want to
add a new one from within this form. If I do this the same data is in the
new form and the first form. What am I doing wrong.
This is what I want.
A folder with a collection of custom forms (ie modified contact-items).
Each form contains vbs and has a combobox and contact fields. This combobox
contains all the forms in the folder. If I select an item from this combobox
the corresponding form should be openend showing corresponding data in the
fields. If I chage a value in one of the fields and press a save button the
corresponding form shown in the combobox should be updated. Sounds easy,
but is not ;-)
Regards
Boein


:

You can't. Outlook provides no method for selecting a particular item in a folder view.

Hi,
Using modified contact forms with vbs. After adding a contact from a
contact the focus is still set on the previous contact if you look at the
selected address cards. How can you set the focus on the added contact.
Thanks
Boein
 
B

Boein

Ok found a solution. I moved the combo-adding procedure to the item_open()
event and added extra lines to the create button so the current item is
closed first a new item is added and next a search to the new item + a
display. In this way it works.

Sue Mosher said:
I'm not sure what value or values you're referring to as "value you want to add." Could you be more specific?

In code behind an Outlook form, the intrinsic Item object always refers to the current item whose form's code is running. If you create a new item and want to work with its controls, you use the same GetInspector method as you use on Item to return the Inspector for the new item:

Set itm = itms.Add("IPM.Contact.structure")
Set insp = itm.GetInspector

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Boein said:
Hi Sue,
I dug a little deeper and for some reason the value you want to add is saved
2 times. One time when calling the add-method and the second time I guess
when changing value on the item I started from (to make a next item). Maybe
the second item made from the first one inherits some values. I just don't
understand it. Next problem. The combobox (scompany) is an unbound control.
To fill it I need to refer to it by using these commands:
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
Set Control = FormPage.Controls("scompany")
how can I be sure that i'm referring to the item i'm working with (the item
that has focus). If I create a new item (add method) followed by a display
and then using these commands result in an error "you don't have the
appropriate permission to perform this operation).


Sue Mosher said:
An easier way to sort the contents for the combo box would be to return the Items collection from the folder and then call its Sort method *before* you iterate the Items collection. Maybe just simplifying the way you load the rows would solve the problem.

Ok you did some nice reverse engineering ;-) If I run the program like this
it works, when press "save" an item it's created and it appears between the
others in de structure folder. But I have a problem with the combobox. The
value of the new created item occurs in the combobox, but the previous item
is also replaced. With previous I mean: the value from the last open item.
Also If i select an item from the combobox it opens the right corresponding
item but if a create a new one, again the new item is added to the combobox
but the previous item in the combobox is again replaced... If I do it again,
the item in the combobox that was wrong is corrected but again the last one
is added and de previous one is wrong...and so on.
The arrays in the program is to order the contents in the combobox.



:

With that code, you're creating an item in the Structure folder using the IPM.Contact.structure form and then setting some values for the new item that you got from the old item. (You got them the hard way -- reading control values when you should have been reading property values.)

This section has the statements out of order:

Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display

Since you closed the original item, there may be no ActiveInspector at all, much less an Inspector for the newly created item. Instead, display the item first, then set its current form page. However, unless you've done a heavy redesign and renamed pages, there is no need to set the "General" page as current. The first page is always the one displayed by default.

The code then fills a combo box on the item with the names of companies in the Structure folder, but I'm not sure I understand the use of two arrays.

What specific problem are you encountering?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Here's some code I use

sub save_click()

Set myItem = Application.ActiveInspector.CurrentItem

Set nms = Application.GetNameSpace("MAPI")
Set FormPage = Item.GetInspector.ModifiedFormPages("General")
t_companyname=FormPage.Controls("companyname").value
t_BusinessAddressStreet= FormPage.Controls("BusinessAddressStreet").value
t_BusinessAddressCity= FormPage.Controls("BusinessAddressCity").value
t_BusinessAddressState= FormPage.Controls("BusinessAddressState").value
t_BusinessAddressPostalCode=
FormPage.Controls("BusinessAddressPostalCode").value
t_BusinessAddressCountry= FormPage.Controls("BusinessAddressCountry").value
t_BusinessTelephoneNumber=
FormPage.Controls("BusinessTelephoneNumber").value
t_BusinessFaxNumber= FormPage.Controls("BusinessFaxNumber").value
myitem.close 1

strFolder = "Structure"
fFound = FindFolder(nms.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld = nms.Folders("Mailbox - PZ").folders("PZ").Folders.Add(strFolder,
olFolderContacts)
End If
Set itms = fld.Items
set itm = itms.find("[companyname] = '" & t_companyname & "'")
if itm is nothing then

Set itm = itms.Add("IPM.Contact.structure")

with itm
.companyname = t_companyname
.BusinessAddressStreet= t_BusinessAddressStreet
.BusinessAddressCity= t_BusinessAddressCity ...BusinessAddressState=
t_BusinessAddressState .BusinessAddressPostalCode=
t_BusinessAddressPostalCode .BusinessAddressCountry=
t_BusinessAddressCountry .BusinessTelephoneNumber=
t_BusinessTelephoneNumber .BusinessFaxNumber= t_BusinessFaxNumber

end with
itm.save
Set myInspector = application.ActiveInspector
myInspector.SetCurrentFormPage ("General")
itm.display
else

end if
call fill_combobox
end sub


function fill_combobox()
Set nms1 = Application.GetNameSpace("MAPI")
Set FormPage1 = Item.GetInspector.ModifiedFormPages("General")
Set Control1 = FormPage1.Controls("scompany")
FormPage1.controls("scompany").clear
strFolder = "Structure"
fFound = FindFolder(nms1.Folders("Mailbox - PZ").folders("PZ").Folders, 0,
strFolder)
If fFound = True Then
Set fld1 = nms1.Folders("Mailbox - PZ").folders("PZ").Folders(strFolder)
ElseIf fFound = False Then
Set fld1 = nms1.Folders("Mailbox -
PZ").folders("PZ").Folders.Add(strFolder, olFolderContacts)
End If
tel=0
Set itms1 = fld1.Items
numitems = itms1.count

numcontacts=0

ReDim FullArray(NumItems-1)

For I = 1 to numitems
set itm1 = itms1(i)
NumContacts = NumContacts + 1
FullArray(NumContacts-1) = itm1.companyname
Next
for i = UBound(FullArray) - 1 To 0 Step -1
for j= 0 to i
if FullArray(j)>FullArray(j+1) then
temp=FullArray(j+1)
FullArray(j+1)=FullArray(j)
FullArray(j)=temp
end if
next
next

control1.ColumnCount = 1

If NumItems = NumContacts Then
control1.List() = FullArray
Else

Dim ConArray()
ReDim ConArray(NumContacts-1,2)
For I = 0 to NumContacts - 1
ConArray(I,1) = FullArray(I)

Next
control1.List() = ConArray

End If
set nms1=nothing
set fld1=nothing
set formpage1=nothing
set control1=nothing
set itm1=nothing
set itms1=nothing
end function




:

Did you try the code I suggested for creating a new item using a custom form?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Hi Sue,

Form and item is exactly like you discribed. The combobox in the form
should be filled dynamicaly when the form is started the form should read a
field of all the other forms and add this field to the combobox. When the
loop is done the combobox is filled and you should be able to select and item
from it and this wil result in displaying the corresponding form.

:

I'm confused over whether you mean "form" and "item" in your description of the contents of the combo box. A form is a code/UI template. It contains no data, although it may have default values for certain fields. An item is the unit of data storage. It is linked to a particular form through the value of its MessageClass property.

So are you talking about published custom forms? Or are you talking about creating new items from existing items (which may or may not be using a custom form)? Or something else completely?

To create a new item that uses a custom form for its UI and code, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

If it's a message form, 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. To create an item in another person's mailbox, use Namespace.GetSharedDefaultFolder to get the MAPIFolder 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.

To create a new item that is a copy of an existing item, call the Copy method on the item you want to copy:

Set newItem = oldItem.Copy


OK then what happens if you're running a form from a folder and you want to
add a new one from within this form. If I do this the same data is in the
new form and the first form. What am I doing wrong.
This is what I want.
A folder with a collection of custom forms (ie modified contact-items).
Each form contains vbs and has a combobox and contact fields. This combobox
contains all the forms in the folder. If I select an item from this combobox
the corresponding form should be openend showing corresponding data in the
fields. If I chage a value in one of the fields and press a save button the
corresponding form shown in the combobox should be updated. Sounds easy,
but is not ;-)
Regards
Boein


:

You can't. Outlook provides no method for selecting a particular item in a folder view.

Hi,
Using modified contact forms with vbs. After adding a contact from a
contact the focus is still set on the previous contact if you look at the
selected address cards. How can you set the focus on the added contact.
Thanks
Boein
 

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