Selection in a list box, which prevents all other controls to operate

Grosraymond

New member
Local time
Today, 04:37
Joined
Mar 30, 2012
Messages
4
Hello,

I try to select by the vba code, one element in a list box.
I found this code on this site:
Code:
[COLOR=#0000ff]Function[/COLOR] Selectionner(Liste [COLOR=#0000ff]As[/COLOR] ListBox, Colonne [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], Chercher [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR])     
[COLOR=#0000ff]Dim[/COLOR] i [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]     [COLOR=#0000ff]
Dim[/COLOR] Trouve [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Boolean[/COLOR]     [COLOR=#0000ff]
For[/COLOR] i = [COLOR=#cc66cc]0[/COLOR] [COLOR=#0000ff]To[/COLOR] Liste.ListCount - [COLOR=#cc66cc]1[/COLOR]         [COLOR=#0000ff]
If[/COLOR] Liste.Column(Colonne, i) = Chercher [COLOR=#0000ff]And[/COLOR] [COLOR=#0000ff]Not[/COLOR] Trouve [COLOR=#0000ff]Then[/COLOR]             
Liste.Selected(i) = [COLOR=#0000ff]True[/COLOR]         
[COLOR=#0000ff]If[/COLOR] Liste.MultiSelect = [COLOR=#cc66cc]0[/COLOR] [COLOR=#0000ff]Then[/COLOR] Trouve = [COLOR=#0000ff]True[/COLOR]        
 [COLOR=#0000ff]Else[/COLOR]             Liste.Selected(i) = [COLOR=#0000ff]False[/COLOR]        
 [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If[/COLOR]     
[COLOR=#0000ff]Next[/COLOR] i   
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Function
[/COLOR]
It works great, the selection is made. The problem is that once I played this code, I can not use any control on the form. The buttons on the form became inactive

Someone has an idea cause i'm lost, i don't find a solution.

Thank you.

P.S: I use Access 2003
 
why do you need any code to select a record in a list box ?

You put some code that you found on the net, don't say what you want to get, and ask us to look for the problem?
 
Ok, sorry if i'm not clear.

I've got 2 forms.
In the first form i've got a button. When i click on it, it open the second form and send to it an OpenArg whiwh contains an id.
On the second form i'v got a list box with a lot of row. I wish to select the row and I want to select the line that has the id passed in the listbox.
On my second form i have two other button to execute some part of code.

When i click on the button of the first form, it passes the id. I get it in the second form. Then, the code i exposed before works and select the gfood row. But after that, others buttons on the second form don't work.

If i comment the code to select the row, my buttons work. It is strange, i don't yunderstand why this code prevent buttons to work.

Sorry for my english, i hope you understand my problem, if not ask me, i'll try to be more clear.
 
I found the solution. I called my function in the open form function. Now i call it in the load function and it works.
Thank's for your help.
 

Users who are viewing this thread

Back
Top Bottom