Solved

Increment/Decrement ComboBox Index

Posted on 2006-06-22
4
899 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
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 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now