Pre selection of a combobox multivalued

cassof

New member
Local time
Yesterday, 19:17
Joined
Apr 16, 2012
Messages
1
Hi everybody

I m working on an access database and i have a problem.
I would like to preselection all items of my combobox multivalued.

Here you are my code with which i recover the good items but i don't suceed to preselected them.

Code:
lBase = 0
If Me.cmdlistIcp8_FNewMsn.ColumnHeads Then lBase = 1
 
' Crée un tableau de valeurs à partir des valeurs de la liste
For l = lBase To Me.cmdlistIcp8_FNewMsn.ListCount - 1
    ReDim Preserve vValues(0 To l - lBase)
    ' CLng pour convertir en entier long car mon champ
    ' contient des valeurs de type entier long.
     'Si le champ contient des valeurs texte, enlever CLng
    vValues(l - lBase) = Me.cmdlistIcp8_FNewMsn.ItemData(l)
Next
 'Affecte le tableau à la propriété Value de la liste
 
For l = 0 To Me.cmdlistIcp8_FNewMsn.ListCount - 1
    MsgBox (" Valeur  : " & l & "   " & vValues(l))
   [FONT=Arial Black][COLOR=red]Me.cmdlistIcp8_FNewMsn.Value = vValues[/COLOR][/FONT]
    
Next

The red line is the cause wich open the debugguer due of : vValues = NULL But MsgBox (" Valeur : " & l & " " & vValues(l)) show me the good value of vValues()

Thx
 

Attachments

  • Help1.jpg
    Help1.jpg
    84.3 KB · Views: 145
Hi,

The messagebox suggests that vvalues is an array, so I think you should change the line giving the error to

Me.cmdlistIcp8_FNewMsn.Value = vValues(l)
 
Errr not quite. Your loop doesn't do anything.

CHeck this link for an example: http://msgroups.net/microsoft.publi...ng-VBA-to-select-Items-in-multiselect-Listbox This applies to a listbox, not a combobox married to a multivalued field.

BTW: I presume we are dealing with a listbox and not a combobox. Further, calling either listbox or combobox with a name beginning with "cmd" - which is often used for buttons - will be utterly confusing for anyone maintaining your code.

If this is a multivalued field, spawning a combobox witt checkbuttons, then my suggestion would be to get rid of the mutlivalued field, becuase it will cause you trouble for ever after.
 

Users who are viewing this thread

Back
Top Bottom