Solved

Combo box dilemma

Posted on 2001-06-05
10
186 Views
Last Modified: 2010-05-02
I have a combo box and I've set the style property to dropdown list and the sorted property to true. I also have a click event procedure linked with this combo box. My dilemma is when I try to place a value from an ADO recordset into the text of the combo box. When the program reaches that line of code it automatically jumps to the associated click event procedure and does an infinite loop there. I need the style property to be in dropdown list so I can prevent entries that aren't in the combo boxes choices but the dropdown list keeps making this problem with the infinite loop.
0
Comment
Question by:ccbfSEARCA
10 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6158272
Hi, why don't you show your codes then ppls can solve it. : )
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6158283
I have no problem doing this, are you sure your code is not in the Change event, I have done that before.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6158455
You should not change the text of the Combo box, in the change event, which will trigger the change event, to put into a loop.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Expert Comment

by:gajendra
ID: 6158509
Please show your code.

Gajendra
0
 
LVL 6

Expert Comment

by:VK
ID: 6158751
Hi, i know your problem.

You get a change-event every time textbox of the ComboBox cahnges its text or you click on the button.

You shouln't call a sub/function in the click-event of a combobox which changes the text of that combo (stack overflow).

If you havent another choice you could set a flag, determining whether the change was initiated from user or from code.

0
 
LVL 1

Accepted Solution

by:
zzconsumer earned 50 total points
ID: 6158815
This is not perfect, but it should work:

- Set a private boolean variable valid for the form you are working on. If you fill the box from another form, set a global boolean variable or use property get/let. This variable is intended to allow the ComboBox to Execute the Click- Event.
- use IF in the first line of the combo box to check the variable. If false, exit sub.
- In your sub that fills up the box and the one which checks it, first set to False and afterwards to True.

Greetings
zz
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6159307
zzconsumer, firstly it is not considered good practice to lock questions by posting an answer in this way. You should have submitted your post as a comment. You do NOT have the one and only 100% definitive answer to this problem.

The "answer" posted by zzconsumer doesn't actually address the problem as I understand it. You are attempting to set the .Text property of the combo box to an item in the list, this does in fact raise the click event when you have finished. A slightly better solution to avoid the re-entrance is to include a static boolean in the event code:

Private Sub Combo1_Click()
    Static blnClicked As Boolean
    If Not blnClicked Then
        blnClicked = True
        Exit Sub
    End If
    Combo1.ListIndex = 1
    blnClicked = False
End Sub

Shows how this avoids the infinite loop.
0
 
LVL 1

Expert Comment

by:zzconsumer
ID: 6160047
Yeah, I know and I'm sorry for that. As I see, I marked 'answer' instead of 'comment' as I was a bit sleepy this morning.
0
 

Author Comment

by:ccbfSEARCA
ID: 6160404
I thought of a similar solution (the reverse of using Exit Sub) just before I read yours. It gets me through the infinite loop and many lines that are unnecessarily read but I was hoping to find a property, setting or something that will totally avoid the Click procedure (unless really clicked). Since our solutions were very similar, grading you was like grading myself. This will do for now but I have a lot of these combo boxes and there is an exponential increase in the number of lines of code that my program has to go through.
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6161949

Just a thought, the following does not fire the Click event

    Combo1.Text = Combo1.List(Index)

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

813 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

18 Experts available now in Live!

Get 1:1 Help Now