Filling listbox on custom Contact item 1st page

G

Guest

I have a custom form for Contacts that has a list box on the 1st page into
which I am reading data from an Excel spreadsheet. Was trying to use the
Join function to do this per pgs 108-109 of Sue's book but can't get past a
run time error on the line that has comment relative to
objItem.lstVisitRequest list box in below code. Can anyone advise me why
this isn't working? Run time error given for this line is #5: Invalid
procedure call or argument, yet it is done in same way as Sue's book.
intRowCount = objRange.Rows.Count
If intRowCount > 0 Then
For Each m_objItem In m_objCurrentFolder.Items
m_strCategories = m_objItem.Categories
If InStr(m_strCategories, "International") > 0 Then
lstVisitRequests.ColumnCount = 4
Dim arrVisitRequests(ListBoxRows, 3)
Dim arrList(ListBoxRows, 3)
For I = 0 To intRowCount
arrVisitRequests(I, 0) = objRange.Cells(I + 1, 1)
arrVisitRequests(I, 1) = objRange.Cells(I + 1, 2)
arrVisitRequests(I, 2) = objRange.Cells(I + 1, 3)
arrVisitRequests(I, 3) = objRange.Cells(I + 1, 4)
Next
' Fill the List Box from the loaded array.
lstVisitRequests.List() = arrVisitRequests
' Fill the List Box in the current contact item
m_objItem.lstVisitRequests = Join(arrVisitRequests, ",")
' above line has run time error
m_objItem.Save
End If
Next
End If
 
S

Sue Mosher [MVP-Outlook]

If you already have this statement:

lstVisitRequests.List() = arrVisitRequests

I don't understand the purpose of this one:

m_objItem.lstVisitRequests = Join(arrVisitRequests, ",")

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Sue,
The line... lstVisitRequests.List() = arrVisitRequests ....reads the array
data into a list box that is resident in the form that is part of my VBA
session and works fine. This is really there to test my read process and
feed process to the list box.
The line....m_objItem.lstVisitRequests = Join(arrVisitRequests, ",").....is
what I am really trying to do, which is fill an identical lstVisitRequests
list box in each objItem as they are being walked thru by the rest of the
code within the For Each...EndIf loop. This list box has identical
properties to the one in the test form referenced above, but resides on the
1st page of the custom form for each contact. Using the Watch feature I
have confirmed that this For Each loop is working properly to walk thru each
contact in the folder. My problem is I can't figure out how to get the
arrVisitRequest data into the list box contained in each objItem list box.
 
S

Sue Mosher [MVP-Outlook]

fill an identical lstVisitRequests
list box in each objItem as they are being walked thru by the rest of the
code within the For Each...EndIf loop

What you want to do is not possible. Changes to an item's UI -- such as filling a list box -- are not persisted when the item is saved. Filling the list box is an operation that needs to take place in the Item_Open event handler on your form.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


John E. said:
Sue,
The line... lstVisitRequests.List() = arrVisitRequests ....reads the array
data into a list box that is resident in the form that is part of my VBA
session and works fine. This is really there to test my read process and
feed process to the list box.
The line....m_objItem.lstVisitRequests = Join(arrVisitRequests, ",").....is
what I am really trying to do, which is fill an identical lstVisitRequests
list box in each objItem as they are being walked thru by the rest of the
code within the For Each...EndIf loop. This list box has identical
properties to the one in the test form referenced above, but resides on the
1st page of the custom form for each contact. Using the Watch feature I
have confirmed that this For Each loop is working properly to walk thru each
contact in the folder. My problem is I can't figure out how to get the
arrVisitRequest data into the list box contained in each objItem list box.
 
G

Guest

Sue,
OK...I understand that the list box after being filled is not persistent
when the contact is saved and would have to be refilled each time the contact
is opened to see the intended content of the list-box.
But it appears to me that the Categories that are created in the Master
Category file and then checked by the user when setting up a contact ARE
persistent...both the category assigned and the check box are visible again
when the saved contact is re-opened. If I can't do what I want to do with a
list-box, is there a way I can replicate the Categories capability with code
and accomplish what I want to do via the establishment of categories?
 
S

Sue Mosher [MVP-Outlook]

It's not at all clear what you're trying to do other than fill a list box. Please fill us in on the bigger picture.

You can also write code behind your form to store the data needed to fill the list box so you can load it from the information in the form during the Item_Open event.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


John E. said:
Sue,
OK...I understand that the list box after being filled is not persistent
when the contact is saved and would have to be refilled each time the contact
is opened to see the intended content of the list-box.
But it appears to me that the Categories that are created in the Master
Category file and then checked by the user when setting up a contact ARE
persistent...both the category assigned and the check box are visible again
when the saved contact is re-opened. If I can't do what I want to do with a
list-box, is there a way I can replicate the Categories capability with code
and accomplish what I want to do via the establishment of categories?
 
G

Guest

Sue,
Finally succeeded in getting the VBA code converted to VBScript so it would
run with my custom form. Everything now works except for one thing, which
is a major shortcoming to the way we want it to work: as you point out, the
filled list box is not persistent and disappears when I save the contact and
attempt to re-open the saved item. I somehow need to resolve that with an
alternative approach that will be persistent.

I belive I understand what you are saying about putting code behind the form
to save the data that initally fills the list box to a separate file, and
then reading that file back in to the list box when the item is opened again.
However, I still want to always check the Excel file upon opening the item
for new data that wasn't in previous versions of the list box, and append any
new data to whatever was previously in the list box. Any suggestions?
 
S

Sue Mosher [MVP-Outlook]

If you're going to check the Excel file every time, why not just use it to fill the list box every time?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Here is why. In our application, at time of initiating a new contact with
the custom form, the list box will be filled and the user will then select
one or more of the check boxes while completing the data in the contact form.
These check box selections need to be preserved after the new contact is
then saved and re-opened the next time. At the next time of opening of the
same contact, I need to read the data back into the list box, but those rows
that were selected in the option check boxes previously need to be reinstated
automatically without the user having to re-check the boxes. Which check
boxes are selected from the total list at time of contact initializaion and
initial list box fill will vary from contact to contact.
I thought about using some code triggered by the Write event in which the
Selected property of the list box would determine in a loop which rows in the
list box were selected and then store this as an array somehow so it could be
used on the next Open event of this specific contact to re-establish which
rows of the new fill need to be re-selected. I think this could be
accomplished, but I am struggling with how to implement it.
 
S

Sue Mosher [MVP-Outlook]

The user's selections are data that should be stored in the Outlook item. Your "thought about using some code" is exactly on target. My sample form at http://www.outlookcode.com/files/FormControlsDemo.zip has an example of how to do this.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Sue,
I studied your FormControlsDemo approach and implemented a VBScript
adaptation of it into my custom contact form to read data into a listbox at
time of the contact form initialization. User then completes the form and
selects one or more of the list boxes before saving the inital item. I
thought everything was doing what I wanted until some more recent testing. I
discovered that whichever list boxes had NOT been checked at time of
initalization could never be checked at a later date. In other words which
ever list box selections were made at time of initialization of the contact,
they were in stone and could not be changed later. Our application requires
the flexibility of being able to select additional boxes at a later date in
the list. How can we do that? Is there another option to keep list box data
from being perishable, but still being able to check additional list itmes at
later date?
 
S

Sue Mosher [MVP-Outlook]

Sorry, but you lost me at "selects one or more of the list boxes." Users can select one or more items in a list box, but I don't know what you mean by selecting the list box itself. You really haven't said anything about whether you're using a multi- or single-select list box, or whether it's bound to an Outlook property, or if so, what.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and 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