?
Solved

Increment/Decrement ComboBox Index

Posted on 2006-06-22
4
Medium Priority
?
911 Views
Last Modified: 2008-03-17
I have a combobox to which I want to be able to increment or decrement the index by clicking a button.

The following is the code I have come up with so far, however, it is not performing the action as expected.

Dim NewIndex As Long

MsgBox Me.CustomerIDCombo.ListIndex

NewIndex = Me.CustomerIDCombo.ListIndex + 1

MsgBox NewIndex

Me.CustomerIDCombo = Me.CustomerIDCombo.ItemData(NewIndex)

MsgBox Me.CustomerIDCombo.ListIndex

My first message box diplays the current combobox index.  The second one shows that the variable NewIndex is set to the listindex plus 1.  The third shows that the index did  not change from the first message box.

I have put in numbers such as "Me.CustomerIDCombo = Me.CustomerIDCombo.ItemData(54)" and the index does change appropriately to the 54th row in the combobox.

It appears to me that the statement "Me.CustomerIDCombo = Me.CustomerIDCombo.ItemData(NewIndex)" is not able to accept the variable NewIndex.  It has been defined as Long....

Any ideas or OTHER ideas would be greatly appreciated.

- Rick






0
Comment
Question by:rtomlinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

by:rtomlinson
ID: 16962818
I think have answered my own question.  It appears that the increment codes to be as follows -

Dim NewIndex As Long
NewIndex = Me.CustomerIDCombo.ListIndex + 2
Me.CustomerIDCombo = Me.CustomerIDCombo.ItemData(NewIndex)

The decrement code is as follows -

Dim NewIndex As Long
NewIndex = Me.CustomerIDCombo.ListIndex
Me.CustomerIDCombo = Me.CustomerIDCombo.ItemData(NewIndex)

This seems to work but I am not clear as to why this works.  I don't like not knowing.  Can someone explain to me without using the words "gremlins" or "magic".

0
 
LVL 34

Accepted Solution

by:
jefftwilley earned 1000 total points
ID: 16964326
Actually in your case it probably is just happy purple smoke. Basically what you're doing is moving through the columns in your combo box to reorder the results. Why this works? blind luck really.

Normally you create an on_click event on your combo box's label and use code like

If label is blue then

       Forms!frm_OEOrders!cbo_OrderNumber.RowSourceType = "Table/Query"
        Forms!frm_OEOrders!cbo_OrderNumber.RowSource = "SELECT ??? From ??? ORDER BY ??? DESC"
        label = red
Else
       Forms!frm_OEOrders!cbo_OrderNumber.RowSourceType = "Table/Query"
        Forms!frm_OEOrders!cbo_OrderNumber.RowSource = "SELECT ??? From ??? ORDER BY ???"
        label = blue
end if

Something like that.
J
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question