Solved

Increment/Decrement ComboBox Index

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 - Labels prompt to print 4 32
Attachment field in SQL 3 28
Progress bar in access form 11 23
Modify report 8 8
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

803 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