L
Lee Harwell
Problem: I am trying to get the multiselect records chosen
from a Listbox (named: NameListBox)(Multiselect property
is set to "Extended") to open up in a form named
NameDetailForm. The following code appears to work up to
the point where the DoCmd OpenForm call breaks down,
causing an error message " Form not open".
After a failed attempt I have opened up the NameDetail
Form in Design view and the correct ComputerNo's have been
added to the Filter. Can you tell why the NameDetailForm
will not open displaying those records?
If you can suggest alternative code that allows me to
accomplish same I would be eternally grateful.
Private Sub cmdSome_Click()
Dim strWhere As String, varItem As Variant
' If no items selected, then nothing to do
If Me!NameListBox.ItemsSelected.Count = 0 Then Exit Sub
' Loop through the items selected collection
For Each varItem In Me!NameListBox.ItemsSelected
' Grab the ISBN column for each selected item
strWhere = strWhere & Chr$(34) & Me!
NameListBox.Column(0, varItem) & Chr$(34) & ","
Next varItem
' Throw away the extra comma on the "IN" string
strWhere = Left$(strWhere, Len(strWhere) - 1)
' Open the books form filtered on the selected books
gstrWhereBook = "[ComputerNo] IN (" & strWhere & ")"
DoCmd.OpenForm FormName:="NameDetailForm",
WhereCondition:=gstrWhereBook
End Sub
from a Listbox (named: NameListBox)(Multiselect property
is set to "Extended") to open up in a form named
NameDetailForm. The following code appears to work up to
the point where the DoCmd OpenForm call breaks down,
causing an error message " Form not open".
After a failed attempt I have opened up the NameDetail
Form in Design view and the correct ComputerNo's have been
added to the Filter. Can you tell why the NameDetailForm
will not open displaying those records?
If you can suggest alternative code that allows me to
accomplish same I would be eternally grateful.
Private Sub cmdSome_Click()
Dim strWhere As String, varItem As Variant
' If no items selected, then nothing to do
If Me!NameListBox.ItemsSelected.Count = 0 Then Exit Sub
' Loop through the items selected collection
For Each varItem In Me!NameListBox.ItemsSelected
' Grab the ISBN column for each selected item
strWhere = strWhere & Chr$(34) & Me!
NameListBox.Column(0, varItem) & Chr$(34) & ","
Next varItem
' Throw away the extra comma on the "IN" string
strWhere = Left$(strWhere, Len(strWhere) - 1)
' Open the books form filtered on the selected books
gstrWhereBook = "[ComputerNo] IN (" & strWhere & ")"
DoCmd.OpenForm FormName:="NameDetailForm",
WhereCondition:=gstrWhereBook
End Sub