Combo selection always the 1st ?

W

Wayne-I-M

Hi

I have an unbound combo [EventCodesCombo] that displayes a filter list of
items.

SELECT [qryEventSorter].[EVTCode] FROM [qryEventSorter];

After update this combo sets the value of another combo

cboEvent = EventCodesCombo.ItemData(0)


The combo [EventCodesCombo] always reverts to the 1st item which ever is
selected.

Any ideas ?

Thank you
 
J

Jeff Boyce

Wayne

If I'm reading your description correctly, you're telling Access to set the
cboEvent to the first item in the list of items in [EventCodesCombo]. When
you use .ItemData(0), that's what you're telling Access.

If you want cboEvent to be the item selected in [EventCodesCombo] (though I
don't understand why you'd set a second combobox to be the value of the item
selected in the first), you could use:

cboEvent = [EventCodesCombo]

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
K

Ken Sheridan

Wayne:

Zero is the index value for the first row in a combo box's list. To refer
to the currently selected row via the ItemData property you'd need to pass
the current ListIndex value to the ItemData property, e.g.

With Me.ActiveControl
Me.cboEvent = .ItemData(.ListIndex)
End With

However, all you need to do is assign the Value of the combo box to the
other control:

Me.cboEvent = Me.ActiveControl

Ken Sheridan
Stafford, England
 
W

Wayne-I-M

Thanks Jeff - don't know why I did that - must be getting stupid in my old
age :)


Oh - the reason for the wierd passing of the combo to the 2nd is that this
is a touch screen application and it was the only way I could reduce the
number of controls on the screen - which I needed to do as all the controls
on the form are around 3cm square.

Many thanks again--
Wayne
Manchester, England.



Jeff Boyce said:
Wayne

If I'm reading your description correctly, you're telling Access to set the
cboEvent to the first item in the list of items in [EventCodesCombo]. When
you use .ItemData(0), that's what you're telling Access.

If you want cboEvent to be the item selected in [EventCodesCombo] (though I
don't understand why you'd set a second combobox to be the value of the item
selected in the first), you could use:

cboEvent = [EventCodesCombo]

Regards

Jeff Boyce
Microsoft Office/Access MVP


Wayne-I-M said:
Hi

I have an unbound combo [EventCodesCombo] that displayes a filter list of
items.

SELECT [qryEventSorter].[EVTCode] FROM [qryEventSorter];

After update this combo sets the value of another combo

cboEvent = EventCodesCombo.ItemData(0)


The combo [EventCodesCombo] always reverts to the 1st item which ever is
selected.

Any ideas ?

Thank you
 
W

Wayne-I-M

Thanks Ken - spotted my mistake again. Mind block when you sit here all day
doing "simple" stuff the basics fly out of your head somewhere :)

Thanks again - your answer (and Jeff's) worked perfectly

--
Wayne
Manchester, England.



Ken Sheridan said:
Wayne:

Zero is the index value for the first row in a combo box's list. To refer
to the currently selected row via the ItemData property you'd need to pass
the current ListIndex value to the ItemData property, e.g.

With Me.ActiveControl
Me.cboEvent = .ItemData(.ListIndex)
End With

However, all you need to do is assign the Value of the combo box to the
other control:

Me.cboEvent = Me.ActiveControl

Ken Sheridan
Stafford, England

Wayne-I-M said:
Hi

I have an unbound combo [EventCodesCombo] that displayes a filter list of
items.

SELECT [qryEventSorter].[EVTCode] FROM [qryEventSorter];

After update this combo sets the value of another combo

cboEvent = EventCodesCombo.ItemData(0)


The combo [EventCodesCombo] always reverts to the 1st item which ever is
selected.

Any ideas ?

Thank you
 
K

Klatuu

If I understand your question, Wayne, you are explicitly assigning the first
value in the combo regardless of what is actually selected:
cboEvent = EventCodesCombo.ItemData(0)
The ItemData property returns the value of the bound column in the list. It
is much like a collection or an array. ItemData(0) will always return the
first row.

I think all you really need is:

cboEvent = EventCodesCombo
 
W

Wayne-I-M

6:55am (been here for an hour - after leaving at 10pm last night)

Just worked it out. OMG one of the questions that other posters tend to ask
in thier 1st month of using access ??

I got the column widths wrong so the bound column was always the ID - in the
AfterUpdate of a combo that filters the combo reverting to the 1st item. Of
course this will always revert to the 1st if all the ID are the same on the
filtering combo.

Doh.

What an idiot I am

Thanks for your answer - great as always

--
Wayne
Manchester, England.



Klatuu said:
If I understand your question, Wayne, you are explicitly assigning the first
value in the combo regardless of what is actually selected:
cboEvent = EventCodesCombo.ItemData(0)
The ItemData property returns the value of the bound column in the list. It
is much like a collection or an array. ItemData(0) will always return the
first row.

I think all you really need is:

cboEvent = EventCodesCombo

Wayne-I-M said:
Hi

I have an unbound combo [EventCodesCombo] that displayes a filter list of
items.

SELECT [qryEventSorter].[EVTCode] FROM [qryEventSorter];

After update this combo sets the value of another combo

cboEvent = EventCodesCombo.ItemData(0)


The combo [EventCodesCombo] always reverts to the 1st item which ever is
selected.

Any ideas ?

Thank you
 

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