CODE
Run-time error '3265':
Item cannot be found in the collection corresponding to the requested name or ordinal.
Item cannot be found in the collection corresponding to the requested name or ordinal.
Hello,
I am running into a runtime error over and over when trying to set up a multilistbox and taking the values from the listbox and plugging them into a SQL statement to filter a query. I am not sure why it is happening but it happens when referencing the ADOBX command
Here's my code, would you happen to see any faults? I have the reference set up for both ADO Ext. 6.0 for DLL and Security and ActiveX Data Objects 2.1 Library
CODE
Private Sub BuildString()
Dim blnQueryExists As Boolean
Dim cat As New ADOX.Catalog
Dim xt As New ADODB.Command
Dim qry As ADOX.View
Dim varItem As Variant
Dim strCodes As String
Dim strSQL As String
blnQueryExists = False
Set cat.ActiveConnection = CurrentProject.Connection
For Each qry In cat.Views
If qry.Name = "qryMultiCompSettings" Then
blnQueryExists = True
Exit For
End If
Next qry
Application.RefreshDatabaseWindow
DoCmd.Echo False
For Each varItem In Me.lstMulti.ItemsSelected
strCodes = strCodes & ", '" & Me.lstMulti.ItemData(varItem) & "'"
Next varItem
If Len(strCodes) = 0 Then
MsgBox "No Item codes selected."
Exit Sub
Else
strCodes = Right(strCodes, Len(strCodes) - 1)
strCodes = "IN(" & strCodes & ")"
End If
strSQL = "SELECT tblComponentSettings.ProductID, tblComponentSettings.ComponentNameID, " & _
"tblComponentSettings.TargetValue, tblComponentSettings.UpperValue, tblComponentSettings.LowerValue " & _
"FROM tblComponentSettings " & _
"WHERE tblComponentSettings.[ComponentNameID] [forms]![frmMultiTarget]![cboMultiComp] " & _
"tblComponentSettings.[ProductID] " & strCodes & ";"
MsgBox strCodes
cat.ActiveConnection = CurrentProject.Connection
[color="red"] Set xt = cat.Views("qryMultiCompSettings").Command [/color]
xt.CommandText = strSQL
Set cat.Views("qryMultiCompSettings").Command = xt
Set cat = Nothing
End Sub
Dim blnQueryExists As Boolean
Dim cat As New ADOX.Catalog
Dim xt As New ADODB.Command
Dim qry As ADOX.View
Dim varItem As Variant
Dim strCodes As String
Dim strSQL As String
blnQueryExists = False
Set cat.ActiveConnection = CurrentProject.Connection
For Each qry In cat.Views
If qry.Name = "qryMultiCompSettings" Then
blnQueryExists = True
Exit For
End If
Next qry
Application.RefreshDatabaseWindow
DoCmd.Echo False
For Each varItem In Me.lstMulti.ItemsSelected
strCodes = strCodes & ", '" & Me.lstMulti.ItemData(varItem) & "'"
Next varItem
If Len(strCodes) = 0 Then
MsgBox "No Item codes selected."
Exit Sub
Else
strCodes = Right(strCodes, Len(strCodes) - 1)
strCodes = "IN(" & strCodes & ")"
End If
strSQL = "SELECT tblComponentSettings.ProductID, tblComponentSettings.ComponentNameID, " & _
"tblComponentSettings.TargetValue, tblComponentSettings.UpperValue, tblComponentSettings.LowerValue " & _
"FROM tblComponentSettings " & _
"WHERE tblComponentSettings.[ComponentNameID] [forms]![frmMultiTarget]![cboMultiComp] " & _
"tblComponentSettings.[ProductID] " & strCodes & ";"
MsgBox strCodes
cat.ActiveConnection = CurrentProject.Connection
[color="red"] Set xt = cat.Views("qryMultiCompSettings").Command [/color]
xt.CommandText = strSQL
Set cat.Views("qryMultiCompSettings").Command = xt
Set cat = Nothing
End Sub
Thank you very much in advanced!!!
Sam
Edit: Decreased blowout width of code
Edited by: LPurvis on Fri Oct 30 19:56:37 EDT 2009.