mutli-select list box problem

L

Lee Harwell

The following code is my failed attempt to get the items picked in a
multi-select List box to then appear in another form named "NameDetailForm".
The NameDetailForm does open but does not show the items picked from the
list box. I believe the end part of my code is flawed, but cannot figure
out what it should correctly be. If there is better code for this purpose, I
would appreciate seeing it.

Private Sub Itemschosen_Click()
Dim strWhere As String, varItem As Variant
If Me!NameListBox.ItemsSelected.Count = 0 Then Exit Sub
For Each varItem In Me!NameListBox.ItemsSelected
strWhere = strWhere & Me!NameListBox.Column(0, varItem) & "'"
Next varItem
strWhere = Left$(strWhere, Len(strWhere) - 1)
strWhere = "[ComputerNo] IN (" & strWhere & ") "
DoCmd.OpenForm "NameDetailForm"
DoCmd.Close acForm, Me.Name

End Sub
 
D

Dirk Goldgar

In
Lee Harwell said:
The following code is my failed attempt to get the items picked in a
multi-select List box to then appear in another form named
"NameDetailForm". The NameDetailForm does open but does not show the
items picked from the list box. I believe the end part of my code
is flawed, but cannot figure out what it should correctly be. If
there is better code for this purpose, I would appreciate seeing it.

Private Sub Itemschosen_Click()
Dim strWhere As String, varItem As Variant
If Me!NameListBox.ItemsSelected.Count = 0 Then Exit Sub
For Each varItem In Me!NameListBox.ItemsSelected
strWhere = strWhere & Me!NameListBox.Column(0, varItem) & "'"
Next varItem
strWhere = Left$(strWhere, Len(strWhere) - 1)
strWhere = "[ComputerNo] IN (" & strWhere & ") "
DoCmd.OpenForm "NameDetailForm"
DoCmd.Close acForm, Me.Name

End Sub

If ComputerNo is a text field, try this:

strWhere = strWhere & "'" & Me!NameListBox.Column(0, varItem) & "',"

If it's a numeric field, try this:

strWhere = strWhere & Me!NameListBox.Column(0, varItem) & ","
 
D

Dirk Goldgar

In
Lee Harwell said:
The following code is my failed attempt to get the items picked in a
multi-select List box to then appear in another form named
"NameDetailForm". The NameDetailForm does open but does not show the
items picked from the list box. I believe the end part of my code
is flawed, but cannot figure out what it should correctly be. If
there is better code for this purpose, I would appreciate seeing it.

Private Sub Itemschosen_Click()
Dim strWhere As String, varItem As Variant
If Me!NameListBox.ItemsSelected.Count = 0 Then Exit Sub
For Each varItem In Me!NameListBox.ItemsSelected
strWhere = strWhere & Me!NameListBox.Column(0, varItem) & "'"
Next varItem
strWhere = Left$(strWhere, Len(strWhere) - 1)
strWhere = "[ComputerNo] IN (" & strWhere & ") "
DoCmd.OpenForm "NameDetailForm"
DoCmd.Close acForm, Me.Name

End Sub

Oops -- in addition to the first modification I posted, you also need to
specify yout criteria when you open the form. Instead of this:
DoCmd.OpenForm "NameDetailForm"

.... use this:

DoCmd.OpenForm "NameDetailForm", _
WhereCondition:=strWhere
 

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