Hi,
I need to find if an item is in a list through Word VBA for a form I have.
For example the following doesn't work.
If cboListBox.Value In ("Toronto", "Mississauga", "Hamilton") then
cboProvince ="Ontario"
Is there some way to do this. Thanks very much for you help in advance
Suzanne
Jezebel - 06 Nov 2006 20:49 GMT
Apart from actually iterating the list, you can do things like --
TestString = "|" & cboListBox.Value & "|"
If instr("|Toronto|Mississauga|Hamilton|", TestString) > 0 then ...
(The |s around the string are so you don't get false hits on substrings.)
This is rather ugly programming though, and hard to maintain if the list is
long. Simpler is to set up a list and simply iterate it.
Simpler still, in this case, is to set up the provinces as part of the
original listbox: set it up as a two-column list (town, province), then set
the width of the province column to zero.
> Hi,
>
[quoted text clipped - 8 lines]
>
> Suzanne
Dave Lett - 06 Nov 2006 20:54 GMT
Hi Suzanne,
This might be a situation where the Select Case statement would be useful:
Select Case cboListBox.Value
Case "Toronto", "Mississauga", "Hamilton"
cboProvince = "Ontario"
Case "Fairfax", "Falls Church", "Springfield"
cboProvince = "Virginia"
Case Else
cboProvince = "No province selected."
End Select
HTH,
Dave
> Hi,
>
[quoted text clipped - 8 lines]
>
> Suzanne
Go - 06 Nov 2006 21:24 GMT
I like this one
thanks
> Hi Suzanne,
>
[quoted text clipped - 24 lines]
> >
> > Suzanne
Helmut Weber - 06 Nov 2006 21:12 GMT
Hi,
there is no a way other than
comparing each item in the one list
against each item in the other list.
Implementations may vary to a great deal,
as Jezebel and Dave have shown.

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"