[AccessD] Determine whether list box control has a selected value

FW Salato Center Salato at ky.gov
Tue Nov 3 15:47:11 CST 2015


Thanks Jack and Charlotte!

Susan H. 

Susan,

Here is the whole routine. Shows how the blnSelected()is used.

Private Sub MoveDown_Click()
'
' with Access Listbox.column(columnindex, row)
           '
           ' Move Items Down
           ' Allow multicolumn items to move
           '
          Dim lngIndex As Long
          Dim lngStarToRow As Long
          Dim blnSelected() As Boolean
10       On Error GoTo Movedown_Click_Error

20        With listbox1
30            ReDim blnSelected(.ListCount) As Boolean
40            For lngIndex = 0 To .ListCount - 1
50                blnSelected(lngIndex) = .Selected(lngIndex)
60            Next

70            lngStarToRow = -1
80            For lngIndex = 0 To .ListCount - 1
90                If blnSelected(lngIndex) Then
100                   If lngStarToRow = -1 Then lngStarToRow = lngIndex
110               Else
120                   If lngStarToRow >= 0 Then
130                   SwapListboxItems listbox1, lngIndex, lngStarToRow
140                       lngStarToRow = -1
150                   End If
160               End If
170           Next
180       End With

190      On Error GoTo 0
200      Exit Sub

Movedown_Click_Error:

210       MsgBox "Error " & Err.number & " in line " & Erl & "  (" &
Err.Description & ") in procedure Movedown_Click of VBA Document Form_formTestListBox"

End Sub

On Tue, Nov 3, 2015 at 4:28 PM, jack drawbridge <jackandpat.d at gmail.com>
wrote:

> Susan,
>
> Here is a snippet
>
> Private Sub MoveDown_Click()
> '
> ' with Access Listbox.column(columnindex, row)
>            '
>            ' Move Items Down
>            ' Allow multicolumn items to move
>            '
>           Dim lngIndex As Long
>           Dim lngStarToRow As Long
>           Dim blnSelected() As Boolean  '<<<boolean array
> 10       On Error GoTo Movedown_Click_Error
>
> 20        With listbox1
> 30            ReDim blnSelected(.ListCount) As Boolean
> 40            For lngIndex = 0 To .ListCount - 1
> 50                blnSelected(lngIndex) = .Selected(lngIndex) ' <set the
> boolean array according to whether the itemis selected or not
> 60            Next
>
>
> Good luck.
>
> On Tue, Nov 3, 2015 at 4:14 PM, FW Salato Center <Salato at ky.gov> wrote:
>
>> I need to write a quick validation snippet for a multi-value list box.
>> This control's Value property always returns Null. What's the 
>> quickest way to determine if something's selected? I don't need the 
>> actual value, just a True/False response - there's an item selected or there isn't.
>>
>> Thanks!
>> Susan H.
>> --
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com
>>
>
>
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list