Codex
Codex

Reputation: 31

Update Display for Combo Box

I have a form with multiple combo boxes, these boxes have 2 column list where column 0 width is zero. All these boxes have row sources defined for their drop down list values.

When I try to over ride the display value of the combo boxes via vb code, it works for few of the controls while doesnt do anything for the rest. So I made an isolated code just to update values of all combo boxes(cbo) and again the same controls pass/fail. Here is the code I am trying to work with, can anyone please tell me why I am unable to update some combo boxes while others work fine?

Thanks!

Sub test()

Dim Ctrl As Control
Dim CtrlName_Combined as String

For Each Ctrl In Forms("frmNewTransaction").Controls

'Name of all combo boxes start with 'cbo' 

If Left(Ctrl.Name, 3) = "cbo" Then
Ctrl = "Hello"
CtrlName_Combined = ctrlName_Combined & Ctrl.Name & " "
End If

Next Ctrl

MsgBox CtrlName_Combined

End Sub

Here is screenshot of the form after code run (All Combo boxes start with cbo): enter image description here

Upvotes: 0

Views: 108

Answers (1)

Codex
Codex

Reputation: 31

Thank you guys for the help. The problem started when few of the combo boxes did not take value when i executed:

forms("FormName").Controls("ComboBoxName")="Some Value which was in the list"

So I tested all my combos by passing them value "Hello" which I know was not in their row source. Strangely so few combos responded and others did not. This was the rabbit hole as all my combos were configured same apart from their row source queries but all had an ID and eName column.

Problem was that few combos were not taking the text values I passed them but turns out that if I gave them Numeric value according to the first column they start responding (what i dont get here is that how some combos behave one way and rest the other way)

Anyway this helped me get past the problem, thought i should share this after bothering you all with it.

Also I am seeing that the question or manner was not well received by the community, would be helpful if someone pointed out what not to do for future references

Thanks Again!

Upvotes: 0

Related Questions