Solved

Control combobox item selections without using events

Posted on 2002-04-24
14
158 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
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 142

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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 142

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 142

Accepted Solution

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

16 Experts available now in Live!

Get 1:1 Help Now