S
Snowman
Good day all,
I have a list box of invoice IDs that I'd like to use as criterion in a
query that returns records matching the invoice ID(s) selected by the user.
Here's what I have so far which generates an error (run time 3265 Item not
found in this collection) pointing to the DELETE command;
Dim iDb As Database
Dim qdef As QueryDef
Dim i As Integer
Dim strSQL As String
Dim strWhere As String
Dim strIN As String
Dim flgSelectAll As Boolean
Dim varItem As Variant
Set iDb = CurrentDb
Dim stDocName As String
stDocName = "qry_900"
strSQL = "SELECT * FROM tbl_freight_remit_archive"
'loop through listbox
For i = 0 To lstBatchID.ListCount - 1
If lstBatchID.Selected(i) Then
strIN = strIN & "'" & lstBatchID.Column(0, i) & "',"
End If
Next i
'remove the last comma of the IN string
strWhere = " WHERE [lstBatchID] in (" & Left(strIN, Len(strIN) - 1) & ")"
iDb.QueryDefs.Delete stDocName
Set qdef = iDb.CreateQueryDef(stDocName, strWhere)
'Open the query
DoCmd.OpenQuery stDocName, acViewNormal
thanks for any advice.
I have a list box of invoice IDs that I'd like to use as criterion in a
query that returns records matching the invoice ID(s) selected by the user.
Here's what I have so far which generates an error (run time 3265 Item not
found in this collection) pointing to the DELETE command;
Dim iDb As Database
Dim qdef As QueryDef
Dim i As Integer
Dim strSQL As String
Dim strWhere As String
Dim strIN As String
Dim flgSelectAll As Boolean
Dim varItem As Variant
Set iDb = CurrentDb
Dim stDocName As String
stDocName = "qry_900"
strSQL = "SELECT * FROM tbl_freight_remit_archive"
'loop through listbox
For i = 0 To lstBatchID.ListCount - 1
If lstBatchID.Selected(i) Then
strIN = strIN & "'" & lstBatchID.Column(0, i) & "',"
End If
Next i
'remove the last comma of the IN string
strWhere = " WHERE [lstBatchID] in (" & Left(strIN, Len(strIN) - 1) & ")"
iDb.QueryDefs.Delete stDocName
Set qdef = iDb.CreateQueryDef(stDocName, strWhere)
'Open the query
DoCmd.OpenQuery stDocName, acViewNormal
thanks for any advice.