[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Increment/Decrement ComboBox Index

Posted on 2006-06-22
4
Medium Priority
?
913 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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