Log in

View Full Version : Solved: combobox that act strange (from my point of view)



white_flag
07-08-2010, 12:46 AM
good morning

I have the following problem: I have two comboboxes that has to be like this
Combo 1
null
TextforCombo1
TextforCombo1
TextforCombo1
TextforCombo1
Combo 2
null
TextforCombo2
TextforCombo2
TextforCombo2
TextforCombo2
then I like to make then work togheter and I give then some logical statements:


Dim Title1 As String, Title2, Title3, Title4
If Me.Controls("ComboBox1").ListIndex > 0 And Me.Controls("ComboBox2").ListIndex > 0 Then
Title1 = Title1 & Me.Controls("ComboBox1").Text
Title2 = Title2 & Me.Controls("ComboBox2").Text
Call FillBM("book1", vbCrLf & Title1 & " + " & Title2)
Title1 = ""
Title2 = ""
ElseIf Me.Controls("ComboBox1").ListIndex = 0 And Me.Controls("ComboBox2").ListIndex > 0 Then
Title3 = Title3 & Me.Controls("ComboBox2").Text
Call FillBM("book1", vbCrLf & Title3)
ElseIf Me.Controls("ComboBox1").ListIndex > 0 And Me.Controls("ComboBox2").ListIndex = 0 Then
Title4 = Title4 & Me.Controls("ComboBox1").Text
Call FillBM("book1", vbCrLf & Title4)
Else: Me.Controls("ComboBox1").ListIndex = 0 And Me.Controls("ComboBox2").ListIndex = 0
Call FillBM("book1", "")
End If

this take the text from Combo 1 and Combo 2 and put it in an bookmark together or not depends what I am choosing. But not the problem: Wen I select some item from the first combobox nothing is happening and the code delete the item from combo 1 and stay like this. If I select an item from the second combo, it is working fine ..and then I can use the combo 1 (it will gone act like the way I want)..so What it is wrong here?

in attachment is an example of the way of the comboboxes are reacting.

fumei
07-12-2010, 09:58 AM
I have said it previously, but you seems to want to choose to be overly complicated...and that always leads to exactly your problem. It becomes hard to follow all the (extraneous) logic steps.

Have you actually Steped Through the situation? - "Wen I select some item from the first combobox nothing is happening and the code delete the item from combo 1 and stay like this. "

I would start there. Use the magic F8 button. You can easily see that a value does go into Book1, and then....you remove it.

The code is doing PRECISELY, EXACTLY, what you tell it to do. No more, no less. The comboboxes are not doing anything - whatsoever - strange. They are doing exactly what you tell them to do.

Are you even aware you are loading the data file twice? Perhaps you have a reason, what I fail to see what that is, which I have mentioned previously.

white_flag
07-19-2010, 08:04 AM
Gerry :) , you are correct again..thx for the "light" ..I fix the issue. F8 is an interesting button that can help a lot..loading data twice (I will look better to the code)..but for the moment I do not have time.
I am moving in an different location (here in Belgium)..and my free time is
compromised. thx again ..and have you an great day.

A.

fumei
07-19-2010, 09:57 AM
F8 is your friend. There are two things that really help when building complicated coding.

1. chunk out your code. That is, build up your code with smaller pieces and call the pieces. Using a VERY small (silly) example:

Sub ThisStuff()
action this
action that
action more of something
action a bunch of things
action and more
action and even more
action and lots more
End Sub
break it up.
Sub TheMainEvent()
Call NumOne
Call NumTwo
Call NumThree
End Sub

Sub NumOne()
action this
action that
action more of something
End Sub

Sub NumTwo()
action a bunch of things
action and more
action and even more
End Sub

Sub NumThree()
action and lots more
End Sub
All the instructions are still there, but in more manageable pieces. This makes debugging MUCH MUCH easier. If something fails, it fails inside of a smaller piece of code.

2. Use the debugging tools available to you. Step-Through is a vital process. I never execute complicated code the first time I try. Ever. I always Step-Through.

Use the Watch window to keep an eye on values that may be critical.

white_flag
07-22-2010, 02:29 AM
Thx again ..you are better then my programming teacher in explaining how the stuff work, but, I guess not all have the gift of teaching.

have an nice day! (greetings from Belgium)

fumei
07-22-2010, 10:37 AM
Thanks from Canada! Mmmmmm, Belgian beer.