• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

Control combobox item selections without using events

Hi Guys:

I have 2 forms A and B but from B
I'd like to control some functionality that is in  
A without any user event in A.

Specifically I have a combobox in A and I want to get an item interacting thru the items that are already loaded in the combobox BUT with no Click event or other user event.
I have this portion of code

Public Sub C()
   
Dim i As Long
       
For i = 0 To cboWorktype.ListCount - 1
        If cboWorktype.ItemData(i) = "Hello" Then
            cboWorktype.ListIndex = i
        End If
Next
end sub

I want to find the item "Hello" that is loaded in the combo.
Listcount is returning back 0 as if there are no items in there, how can I detect that the items are there with no user events?

Many Thanks
Manolito
0
manolito
Asked:
manolito
1 Solution
 
manolitoAuthor Commented:
I forgot to tell u guys that I'm calling
the Sub "C" from the form B
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
You could use the events in the formB also:

Private WithEvents c As ComboBox
Private Sub c_Change()
  etc...
End Sub

only the the c variable with the combobox of form a:
Private Sub Form_Load()
  set c = formA.cboWorktype
end Sub
Private Sub Form_unload()
  set c = nothing
end Sub

Cheers
0
 
corvanderlindenCommented:
If cboWorktype.ItemData(i) = "Hello"

Itemdata is a long integer, NOT a string

Use
If cboWork.List(i) = "Hello"

Then it works (tested it)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
manolitoAuthor Commented:
corvanderlinden OK I'm using
cboWork.List, but still getting
-1 when I check the ListIndex property
of the combo, I don't know why when
I try to manipulate data from an
external form, the combobox value is set
to -1

thanks
manolito
0
 
manolitoAuthor Commented:
corvanderlinden OK I'm using
cboWork.List, but still getting
-1 when I check the ListIndex property
of the combo, I don't know why when
I try to manipulate data from an
external form, the combobox value is set
to -1

thanks
manolito
0
 
manolitoAuthor Commented:
angelIII I'll try what your saying
I'm not sure if using withevents
will make reference to the same instance
of the combobox

THanks

Manolito
0
 
manolitoAuthor Commented:
angelIII I'll try what your saying
I'm not sure if using withevents
will make reference to the same instance
of the combobox

THanks

Manolito
0
 
manolitoAuthor Commented:
AngelIII, I used with Events
but when I try to ready the Listindex
property of the combobox from form A in Form B
I'm getting -1, as if there are no items.
any other clue?
Thanks guys
0
 
manolitoAuthor Commented:
Guys I'll increase the points.
Any other clues on how to manipulate
comboxes from other forms?.
Is this possible in VB?. The data
is already loaded in the combo,
I just wanted to take the same functionality
in other form as if the user would be clicking in the combo of the orignal form where the combo is placed.

The original form still loaded and behind the one
where I'm triggering the event.

Thanks

Manolito


0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Can you send us your actual project?
The only thing i could think of is that you are checking the value BEFORE the value is set by the procedure C(), or that it is reset by some other event, or that the procedure doesn't change it, as it doesn't find the value "Hello" in the combobox.
Have you used the debug functionality of VB to check out the above things?

CHeers
0
 
manolitoAuthor Commented:
OK Angeliii "C" is just a dummy
procedure that I'm calling from form B
the content of the sub "C" has to
loop thru the combobox to look for
the value but finds it as empty
with Listindex -1 and Listcount = 0 values,
even when I have 120 items already loaded in this combo

Cheers
Manolito
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
!!!!! now i see what's the problem most probably !!!!!
( Silly problem :-)

The problem that you have is that you don't refer to the same instance of formA, when calling the Sub C().

I guess that formA is your startup form, and you will only have this form display once. Then you should add give formB a way to get the true instance of formA.
"add" a module where you place this:
  public gFormA as FormA
  in the formA' load sub:
  set gFormA = me
  in the formA' unload sub:
  set gFormA = nothing
  in FormB, refer to formA only by using gFormA, then your code will work.

Cheers  
0
 
twalgraveCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- answered by angelIII
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

twalgrave
Cleanup Volunteer
0
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now