Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change combo box listindex property 1

Status
Not open for further replies.

GShen

MIS
Sep 26, 2002
561
US
Hi,
Is there any way to change the LISTINDEX property on a combo box?

EX. I have say 3 entries in a combobox. The user selects the 1st. In VBA after I process the entry I want to change the value to the next entry. Orig. set to 0, I want to change to the next entry which will be 1 and keep rolling automatically without to the end of the combo box and then start over again.
The formula would be something like this.

cbobox.listindex = cbobox.Listcount - ((cbobox.Listcount - (cbobox.listindex + 1))

I think that will work, if not I will have to monkey with the formula again. My real issue is being able to change the value of the listindex.

If I confused you please let me know.
Thanks.

Remember when... everything worked and there was a reason for it?
 
Will not work, listindex is read only. What are you trying to do?
 
I found that out. Thanks.
Here is what I am trying to do. An example might be better.
I have a combo box. It contains a list of say 10 printers.
(It can be 10 of anything.) Say I select the 1st entry. (eg. Printer 1). I now lock down the combo box. When the user prints an invoice I print to Printer 1. I now want to select Printer 2 as my next printer in the combo box. The next time the user prints it would user Printer 2. So on and so forth and then wrap back to Printer 1 again. Everything works manually but I am trying to get this automation in. I have a few applications which the users keep using the same printer regardless. I want them to get even distribution. There are other reasons also but it not really relevant. Is there anyway of doing this? I saw something about a dropdown if I declare the combo box as a control but I could not get it to work and I am not sure what that is going to do for me.
Note: When I flip to the next entry I want it to appear in the entry for the combo box so they can see what the new value will be.
Is all of this a reach or can it be done?

Thanks

Remember when... everything worked and there was a reason for it?
 
I am not sure that i would do this with a combo box, it would seem to me that you could do this much nicer with radio buttons. Then you could highlight what printer is coming up next. But this will cycle your combo box if you desire and show the next available printer.

Code:
Private Sub Combo0_AfterUpdate()
  cycleCombo ("Combo0")
End Sub


Public Sub cycleCombo(strCmboName)
  Dim intListIndex As Long
  With Me.Controls(strCmboName)
  If .Enabled Then
    .Locked = True
  End If
  
  If .ListCount - 1 <> .ListIndex Then
    intListIndex = (.ListIndex + 1)
  End If
  .Value = .ItemData(intListIndex)
 End With
End Sub

Private Sub Command2_Click()
  cycleCombo ("Combo0")
End Sub

Private Sub Form_Load()
  Me.Combo0.Locked = False
End Sub

This will work assuming that the bound column in the list box or combo box is unique.
 
Majp,
Ok, I came in with a brainstorm this morning. I got it working. 1st of all I need the combo box vs. the radio buttons because my list of printers can change dynamically.
Today I may have 6, tomorrow 2 don't work and my list will only show 4. I dynamically load the combo box when the form is opened. 2nd of all... ready for this? You can change the listindex! I saw somewhere on microsoft an example of how it is done on double click, not that I want to double click but the key is setting focus to the combo box 1st! It works, I have it in production already. I am going to keep your code in case something does get out of kilter but for now I am in good shape.
Thanks a million. Onto bigger and better things.


Remember when... everything worked and there was a reason for it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top