list box multiple selection code

G

Guest

I have a list box that is set for a single selection. I need to change it to
a multiple selection. my problem is I have coding that works with the single
selection and I
do not know how to get it to work with multple selections. I have two
different events running. On the first one below I am taking the item
selected and
and running the code below which changes data in the item, I now need it to
change the data one at a time on all lines selected. How can I get the same
code to work if they selected multiple items?

On the second code below I am setting the rowsource code per the item
selected.
Now I need it to be the first item selected, or the item closest to the top
of the
list selected.

Any help would be greatly appreciated.

-----FIRST EVENT
Private Sub CmdUP_Click()
On Error GoTo Err_CmdUP_Click

Dim route As String
Dim num As Integer
Dim newnum As Integer
Dim Circ As String
Dim id As Integer

DoCmd.SetWarnings False

'If IsNull(listCircList.Value) Then
If IsNull(Me.listCircList.Column(0)) Then
MsgBox "Must Select RaceWay to Move"
Else
id = Me.listCircList.Column(0)
Circ = Me.listCircList.Column(1)
route = Me.listCircList.Column(2)
num = Me.listCircList.Column(3)
newnum = num - 1
If num = 1 Then
MsgBox "Cannot move up already at Top of List"
Else
DoCmd.RunSQL "Update EleCircuitRoute set routenum = " & num & " where
circuit = '" & Circ & "' and routenum = " & newnum & ""
DoCmd.RunSQL "Update EleCircuitRoute set routenum = " & newnum & " where
ID = " & id & ""
Me.Refresh
End If

End If
END SUB

-----SECOND EVENT
Private Sub listCircList_Click()
Dim Circ As String
Dim strSql As String
Dim route As String
If IsNull(listCircList.Value) Then
Circ = ""
route = ""
Else
route = Me.listCircList.Column(3)
End If
strSql = "SELECT qryCircuitRouteID.Circuit, qryCircuitRouteID.CableType FROM
qryCircuitRouteID WHERE (((qryCircuitRouteID.RouteDesc)=""" & route & """))
ORDER BY qryCircuitRouteID.Circuit;"
listCircPerRW.RowSource = strSql
strSql = "Select qryRaceway.RWMat, qryRaceWay.Diameter FROM qryRaceway Where
(((qryRaceway.LineNumber)=""" & route & """)) order by qryRaceway.LineNumber;"
listRWInfo.RowSource = strSql
End Sub
 
G

Guest

I found some code useing a for next on item selected, but when I use it I get
an error that says. Invalid use of null. below is the code I am using. Also,
I still do not
know how to find the item selected with the smallest number in column 4

CircID = Me.id.Value

For Each varItem In Me.listCircList.ItemsSelected
id = Me.listCircList.Column(0)
num = Me.listCircList.Column(4)
newnum = num - 1
If num = 1 Then
MsgBox "Cannot move up already at Top of List"
Else
DoCmd.RunSQL "Update EleCircRoute set routenum = " & num & "
where CircID = " & CircID & " and routenum = " & newnum & ""
DoCmd.RunSQL "Update EleCircRoute set routenum = " & newnum
& " where ID = " & id & ""
Me.Refresh
End If
Next varItem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top