Combobox: getting 1st column 
Author Message
 Combobox: getting 1st column

Hi All,

I have an unbound form that I populate when the form opens.  The comboboxes
have two columns.  The first column is the unique identifier and the second
column is the actual value for the user to select.  The user does not see
the first column.

I need the value of the first column associated with the value the user
typed in (values limited to list) or selected.  The following code works
only if the user selected from the combobox:

        UserValue = formname!cboName.ItemData(formname!cboName.ListIndex)

However, this doesn't seem to work if the user types in the value rather
than selecting it.  How do I get a sure fire way to get the first column
value associated with the text displayed in the combobox?  I did write a
utility function that would look up the text in the second column, but if
the displayed column was not unique it's worthless.  Your input would be
much appreciated!

--

Thanks,

Zmerz

To reply to my email address please remove _NoSPAM.



Mon, 21 May 2001 03:00:00 GMT  
 Combobox: getting 1st column
If you need to force the user to select only items in the drop down list,
try using a combobox control with the style setting 2
(vbComboDrop-DownList ).  This will prevent the user from typing in a value.
John
Quote:

>Hi All,

>I have an unbound form that I populate when the form opens.  The comboboxes
>have two columns.  The first column is the unique identifier and the second
>column is the actual value for the user to select.  The user does not see
>the first column.

>I need the value of the first column associated with the value the user
>typed in (values limited to list) or selected.  The following code works
>only if the user selected from the combobox:

>        UserValue = formname!cboName.ItemData(formname!cboName.ListIndex)

>However, this doesn't seem to work if the user types in the value rather
>than selecting it.  How do I get a sure fire way to get the first column
>value associated with the text displayed in the combobox?  I did write a
>utility function that would look up the text in the second column, but if
>the displayed column was not unique it's worthless.  Your input would be
>much appreciated!

>--

>Thanks,

>Zmerz

>To reply to my email address please remove _NoSPAM.



Mon, 21 May 2001 03:00:00 GMT  
 Combobox: getting 1st column
That wasn't the question.

I too have had that problem where a value gets entered (somehow other than
selecting) and the code, which normally looks for the associated ID, doesn't
get it because the ID is only available when the item is physically
selected.

Quote:

>If you need to force the user to select only items in the drop down list,
>try using a combobox control with the style setting 2
>(vbComboDrop-DownList ).  This will prevent the user from typing in a
value.
>John


>>Hi All,

>>I have an unbound form that I populate when the form opens.  The
comboboxes
>>have two columns.  The first column is the unique identifier and the
second
>>column is the actual value for the user to select.  The user does not see
>>the first column.

>>I need the value of the first column associated with the value the user
>>typed in (values limited to list) or selected.  The following code works
>>only if the user selected from the combobox:

>>        UserValue = formname!cboName.ItemData(formname!cboName.ListIndex)

>>However, this doesn't seem to work if the user types in the value rather
>>than selecting it.  How do I get a sure fire way to get the first column
>>value associated with the text displayed in the combobox?  I did write a
>>utility function that would look up the text in the second column, but if
>>the displayed column was not unique it's worthless.  Your input would be
>>much appreciated!

>>--

>>Thanks,

>>Zmerz

>>To reply to my email address please remove _NoSPAM.



Mon, 21 May 2001 03:00:00 GMT  
 Combobox: getting 1st column
Normally, if you select an item, the ListIndex is set to that item.  If you
manually enter a value, even if it matches an item in the list, the
ListIndex is set to -1.  If the ListIndex is -1, you can perform a search of
the displayed list and when a match is found, associate the manually entered
information with the ID for the matching item.  If a match is not found,
reject the manually entered information as being invalid or, if necessary,
create a new unique ID and add the item and the new ID to the list.

The original post stated the following:

"I need the value of the first column associated with the value the user
typed in (values limited to list) or selected."

I interpret "values limited to list"  as meaning the manually entered
information must match an item in the displayed list.  That is why I
suggested setting the Style property = vbComboDrop-DownList.  That setting
prevents the user from manually entering information and forces the user to
select from the list.

If I am still missing the point, let me know.
John

Quote:

>That wasn't the question.

>I too have had that problem where a value gets entered (somehow other than
>selecting) and the code, which normally looks for the associated ID,
doesn't
>get it because the ID is only available when the item is physically
>selected.



Tue, 22 May 2001 03:00:00 GMT  
 Combobox: getting 1st column
Hi John,

I tried your first suggestion about changing the style setting to 2.  But
since I am using an unbound form and populate the data in the combo box I
was getting a read-only error.  I tried changing the property on the fly
after the form was populated but that gave me the same type error.  I had
no idea about the -1, I never could figure out where it kept coming from.
I'll trap for the -1 and see where that takes me.  Thanks for your answer.
--

Thanks,

Zmerz

To reply to my email address please remove _NoSPAM.



Quote:
> Normally, if you select an item, the ListIndex is set to that item.  If
you
> manually enter a value, even if it matches an item in the list, the
> ListIndex is set to -1.  If the ListIndex is -1, you can perform a search
of
> the displayed list and when a match is found, associate the manually
entered
> information with the ID for the matching item.  If a match is not found,
> reject the manually entered information as being invalid or, if
necessary,
> create a new unique ID and add the item and the new ID to the list.

> The original post stated the following:

> "I need the value of the first column associated with the value the user
> typed in (values limited to list) or selected."

> I interpret "values limited to list"  as meaning the manually entered
> information must match an item in the displayed list.  That is why I
> suggested setting the Style property = vbComboDrop-DownList.  That
setting
> prevents the user from manually entering information and forces the user
to
> select from the list.

> If I am still missing the point, let me know.
> John


> >That wasn't the question.

> >I too have had that problem where a value gets entered (somehow other
than
> >selecting) and the code, which normally looks for the associated ID,
> doesn't
> >get it because the ID is only available when the item is physically
> >selected.



Wed, 23 May 2001 03:00:00 GMT  
 Combobox: getting 1st column
If you set the style to 2, you can not set the combo's Test property - that
is where the error is being generated. With the style 2, you have to select
items by setting the listbox ListIndex property to a valid item index (0=
first, List.ListCount -1 = last), or to -1 to clear any selected item and
display a empty combo text.

--

Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

To assist in maintaining this thread for the benefit of
others, please post any response to this newsgroup.

Quote:

>Hi John,

>I tried your first suggestion about changing the style setting to 2.  But
>since I am using an unbound form and populate the data in the combo box I
>was getting a read-only error.  I tried changing the property on the fly
>after the form was populated but that gave me the same type error.  I had
>no idea about the -1, I never could figure out where it kept coming from.
>I'll trap for the -1 and see where that takes me.  Thanks for your answer.
>--

>Thanks,

>Zmerz

>To reply to my email address please remove _NoSPAM.



>> Normally, if you select an item, the ListIndex is set to that item.  If
>you
>> manually enter a value, even if it matches an item in the list, the
>> ListIndex is set to -1.  If the ListIndex is -1, you can perform a search
>of
>> the displayed list and when a match is found, associate the manually
>entered
>> information with the ID for the matching item.  If a match is not found,
>> reject the manually entered information as being invalid or, if
>necessary,
>> create a new unique ID and add the item and the new ID to the list.

>> The original post stated the following:

>> "I need the value of the first column associated with the value the user
>> typed in (values limited to list) or selected."

>> I interpret "values limited to list"  as meaning the manually entered
>> information must match an item in the displayed list.  That is why I
>> suggested setting the Style property = vbComboDrop-DownList.  That
>setting
>> prevents the user from manually entering information and forces the user
>to
>> select from the list.

>> If I am still missing the point, let me know.
>> John


>> >That wasn't the question.

>> >I too have had that problem where a value gets entered (somehow other
>than
>> >selecting) and the code, which normally looks for the associated ID,
>> doesn't
>> >get it because the ID is only available when the item is physically
>> >selected.



Thu, 24 May 2001 03:00:00 GMT  
 Combobox: getting 1st column
The Style property needs to be set at design time, not runtime.  If you
attempt to change the style property in code you will generate an error.  If
you need to then place default text in the combo's text property, follow
Randy's suggestion and set the ListIndex to the item from the list  you want
displayed as a default.
John
Quote:

>Hi John,

>I tried your first suggestion about changing the style setting to 2.  But
>since I am using an unbound form and populate the data in the combo box I
>was getting a read-only error.  I tried changing the property on the fly
>after the form was populated but that gave me the same type error.  I had
>no idea about the -1, I never could figure out where it kept coming from.
>I'll trap for the -1 and see where that takes me.  Thanks for your answer.
>--

>Thanks,

>Zmerz

>To reply to my email address please remove _NoSPAM.



Thu, 24 May 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Combobox: getting 1st column

2. combobox: getting 1st column

3. Combobox: getting 1st column

4. Select ComboBox Item by 1st Letter

5. MSFlexGrid, merging 2 columns in the 1st row

6. Formatting columns in a multi-column ComboBox

7. Getting the Column Name of the Primary Key Column

8. Adding excel columns to combobox?

9. Referencing a combobox value and the concept of the bound column

10. Referencing unbound columns of combobox

11. Multi-Column Data-Bound ComboBox

12. Multi column ComboBox in UserForm

 

 
Powered by phpBB® Forum Software