Я пытаюсь создать оператор SQL для применения к источнику записей формы; Я пытаюсь адаптировать некоторый код, который я нашел в Интернете. Этот код прикреплен к событию нажатия кнопки. Однако код возвращает все записи, связанные с полем «Тип корректирующего действия», который я попытался присвоить переменной «TypeList» (код ниже). Может кто-нибудь помочь мне выяснить, почему код возвращает все значения, а не фильтрует значения, выбранные в поле «тип корректирующего действия»?
Dim filtersql1 As String
Dim qrySql As String
Dim EntriesList As String
Dim TypeList As String
Dim VarItem As Variant
For Each VarItem In Me.lstType.ItemsSelected
TypeList = TypeList & ",'" & Me.lstType.ItemData(VarItem) & "'"
Next VarItem
If Len(TypeList) = 0 Then
TypeList = "Like '*'"
Else
TypeList = Right(TypeList, Len(TypeList) - 1)
TypeList = "IN(" & TypeList & ")"
End If
qrySql = "SELECT [Journal Voucher].TAS, [Journal Voucher].Category, [Journal Voucher].[Type of Corrective Action], [Journal Voucher].[VOUCHER#], [Journal Voucher].[Treas-GFMS Variance], " & _
"[Journal Voucher].[JV Reversal Amt], [Journal Voucher].[Original Variance Date], [Journal Voucher].[Corrective Action AP], [Journal Voucher].[Consolidated Log], [Journal Voucher].Offset, " & _
"[Journal Voucher].[AP Added to DB], [Journal Voucher].[Date Added to DB], [Journal Voucher].[Ready to Submit], [Journal Voucher].[Date Submitted], [Journal Voucher].[Date of Reversal JV], " & _
"[Journal Voucher].[Fiscal Year] FROM [Journal Voucher] "
filtersql1 = "WHERE [Journal Voucher].TAS= '" & Me.lstEntries.Value & "' AND [Journal Voucher].[Type of Corrective Action] & TypeList;"
qrySql = qrySql & filtersql1
Debug.Print qrySql
DoCmd.OpenForm "Journal Voucher", acFormDS
Forms![Journal Voucher].RecordSource = qrySql
End Sub