473,408 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Problem with listbox selecting an item

25
Hello,

I have a form with various controls but to simplify the problem let’s say I have 2 listboxes. The selection in listbox1 controls RowSource of the listbox2. For example lstCars contains car models, if I select car model X then lstColors should give me available colors for that particular model. The problem is if I select car model X in lstCars, I want the first color in lstColors to be selected by default.

Here is a sample code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub lstCars_AfterUpdate()
  2.    Call SetColors()  
  3.  
  4.    ‘problem is in the following statements:
  5.    If Me.lstColors.ListCount > 0 And Me.lstColors.ItemsSelected.count < 1 then
  6.        Me.lstColors.Selected(1) = True
  7.    End If
  8. End Sub
  9.  
  10. ‘function to change rowsource of lstColors to correspond to selection in lstCars
  11. SetColors()
  12.    Me.lstColors.RowSource = “Select Color From [tbl Cars] Where Model = ‘”   &    me.lstCars.column(0) & “’”
  13. End sub
After the code is executed. Item in lstColors locks up and no more changes can be done in that listbox. I think sub "lstCars_AfterUpdate" is being called if I click on any item in lstColors, always selecting the first item.
I’m not sure what is going wrong but obviously I’m missing something, Please help.
Feb 7 '08 #1
3 1600
NeoPa
32,556 Expert Mod 16PB
I can't see a problem.
Try using the debugging facilities (Debugging in VBA) to identify whereabouts your code is differing from what you expect it to do.
Feb 7 '08 #2
is49460
25
I've changed event from AfterUpdate to BeforeUpdate and it appears to work fine... I need to look more into it. I dont have an expaination why, but that change solved the problem.
Feb 8 '08 #3
NeoPa
32,556 Expert Mod 16PB
Well, good for you.

I must admit, I can't see why that would have any effect.
I'm glad it's working for you anyway :)
Feb 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
2
archulu
by: archulu | last post by:
hai this archulu Any one help to me, in my project i am using Domapi script for creating Listbox. the main problem is i am creating one button, when that button clicking Listbox(Domapi) was...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.