Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Control combobox item selections without using events

Posted on 2002-04-24
14
Medium Priority
?
182 Views
Last Modified: 2010-05-02
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
Comment
Question by:manolito
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 

Author Comment

by:manolito
ID: 6965241
I forgot to tell u guys that I'm calling
the Sub "C" from the form B
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6965258
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
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 6965319
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:manolito
ID: 6965666
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
 

Author Comment

by:manolito
ID: 6965683
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
 

Author Comment

by:manolito
ID: 6965704
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
 

Author Comment

by:manolito
ID: 6965830
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
 

Author Comment

by:manolito
ID: 6966039
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
 

Author Comment

by:manolito
ID: 6966171
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6967818
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
 

Author Comment

by:manolito
ID: 6967960
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 340 total points
ID: 6967971
!!!!! 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
 
LVL 16

Expert Comment

by:twalgrave
ID: 7895381
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
 

Expert Comment

by:SpideyMod
ID: 7941741
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

609 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