Solved

Increment/Decrement ComboBox Index

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

830 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