?
Solved

Control combobox item selections without using events

Posted on 2002-04-24
14
Medium Priority
?
176 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
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.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

762 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