Get text from keyword Listbox

  • Thread starter Michael Anderson
  • Start date
M

Michael Anderson

Hi,

i am working on a customised contact form. I have a keyword type ListBox
"ListBox3" with a field called "mxzNCRL2". It has 3 possible values:
Bunnings;Forklift;First Aid. I am trying to get the selected value or values
onto a text variable.

Dim txtmxzNCRL2
Dim objInspector

Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\testfile.txt", True)

Set objInspector = Item.GetInspector

txtmxzNCRL2 = Item.UserProperties("mxzNCRL2").Value

MyFile.WriteLine(txtmxzNCRL2)

MyFile.Close

Set fso = Nothing
Set objInspector = Nothing

I am told that I have a type mismatch and it doesn't read in the selected
value or values.

Any suggestions?
 
H

Hollis D. Paul

txtmxzNCRL2 = Item.UserProperties("mxzNCRL2").Value
That line doesn't make a bit of sense to me.

Take a look at these pages and look for coding examples on
www.outlook-code.com and www.slipstick.com concerning listboxes.

To populate a combo box on a Microsoft Outlook form 8/9/2005
Microsoft Outlook VBScript code sample to populate a combo or list box
on an Outlook form using an ADO disconnected recordset
http://www.outlookcode.com/d/code/popcombobox.htm - 21 KB


TIP: To get help with Microsoft Outlook programming objects
8/9/2005
Tip on how to use the Object Browser as an index to get more
information on Outlook model objects
http://www.outlookcode.com/d/tips/gethelp.htm - 15 KB


Microsoft Outlook Developer Tips 8/9/2005
Tips for developing applications with Microsoft Outlook
http://www.outlookcode.com/d/tips.htm - 19 KB


Controls on Microsoft Outlook Custom Forms 8/18/2005
Tips, tricks and other resources for using controls on Microsoft
Outlook forms
http://www.outlookcode.com/d/formcontrols.htm - 34 KB

Hollis D. Paul [MVP - Outlook]
Mukilteo, WA USA
 
M

Michael Anderson

Sorry if my original code wasn't clear. I have slightly modified this but
still no joy:

As I said, I am working on a customised contact form. I have a keyword type
ListBox "ListBox3" with a field called "mxzNCRL2". It has 3 possible values:
Bunnings;Forklift;First Aid. I am trying to get the selected value or values
onto a text variable, "txtmxzNCRL2". No selected keyword prints out.
Supporting documentation doesn't discuss this.

Dim txtmxzNCRL2
Dim objInspector
Dim objPage

Set txtmxzNCRL2 = objPage.Controls("ListBox3")
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\testfile.txt", True)
Set objInspector = Item.GetInspector

MyFile.WriteLine(txtmxzNCRL2.Value)

MyFile.Close

--
Thank You in Advance,

Michael Anderson


Hollis D. Paul said:
txtmxzNCRL2 = Item.UserProperties("mxzNCRL2").Value
That line doesn't make a bit of sense to me.

Take a look at these pages and look for coding examples on
www.outlook-code.com and www.slipstick.com concerning listboxes.

To populate a combo box on a Microsoft Outlook form 8/9/2005
Microsoft Outlook VBScript code sample to populate a combo or list box
on an Outlook form using an ADO disconnected recordset
http://www.outlookcode.com/d/code/popcombobox.htm - 21 KB


TIP: To get help with Microsoft Outlook programming objects
8/9/2005
Tip on how to use the Object Browser as an index to get more
information on Outlook model objects
http://www.outlookcode.com/d/tips/gethelp.htm - 15 KB


Microsoft Outlook Developer Tips 8/9/2005
Tips for developing applications with Microsoft Outlook
http://www.outlookcode.com/d/tips.htm - 19 KB


Controls on Microsoft Outlook Custom Forms 8/18/2005
Tips, tricks and other resources for using controls on Microsoft
Outlook forms
http://www.outlookcode.com/d/formcontrols.htm - 34 KB

Hollis D. Paul [MVP - Outlook]
Mukilteo, WA USA
 
H

Hollis D. Paul

MyFile.WriteLine(txtmxzNCRL2.Value)
That makes more sense, as you are now referencing the control. As far
as I recall, the list options are an array, and you have use the index
value of the control to pick the value out of the array. I don't
remember at all how they do multi-values.

Historically, VBScript is a cut down version of VB4. You really need
to look up, in a VB4 book, how such a control is used. It isn't always
the same, because VBScript is a cut down version. But that is where
you should start. I would suggest asking in a VBA newsgroup, like
public.VB.Controls, if that still exists, or
public.office.developer.vba.

Hollis D. Paul [MVP - Outlook]
Mukilteo, WA USA
 
S

Sue Mosher [MVP-Outlook]

You cannot access the value of a custom keywords property directly. Instead, you must go through the control: To get the selected values from a multi-select list box, you cannot use ListIndex. Instead, you need to loop through all the items in the list and check the Selected property for each one. Form with sample code at http://www.outlookcode.com/files/FormControlsDemo.zip

For more info on working with list boxes, see http://www.outlookcode.com/d/formcontrols.htm#listcombo
--
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