Giúp lỗi Run-time error 3075 của câu lệnh SQL khi tạo report theo checkboxes
Chào các bạn,
Mình đang tạo Report theo các tuỳ chọn của Checkbox, mọi thứ ok chỉ đến câu lệnh chạy SQL tạo Query thì bị lỗi Run-time error 3075 / Syntax error in query expression 'SELECT * FROM tblCC1 WHERE VDNo In(7,8,)'
Lỗi này khá lạ vì khi mình giả lập chính xác câu lệnh này trên 1 query mới thì vẫn chạy ra kết quả. bạn nào có kinh nghiệm vụ này giúp mình với. Cảm ơn.
——————
Private Sub cmdOpenRpt_Click() Dim fonctionQryString As String Dim lngLoopNum As Long Dim strControlName As String Dim strValueList As String For lngLoopNum = 1 To 4 Select Case lngLoopNum Case 1 strControlName = "7" Case 2 strControlName = "8" Case 3 strControlName = "9" Case 4 strControlName = "10" End Select If Me.Controls("ckbVD" & strControlName) = True Then strValueList = strValueList & strControlName & "," End If Next If Len(strValueList) > 0 Then fonctionQryString = "SELECT * FROM tblCC1 WHERE VDNo IN(" & strValueList & ")" Else MsgBox "You must check a Fonction Checkbox" End If DoCmd.OpenReport "qryCC1Report", acViewPreview, , fonctionQryString End Sub
Tôi nghĩ ngay chổ tôi tô màu đỏ, bạn cần xử lý lại chuổi truy vấn, nó sẽ dư 1 dấu phẩy ở cuối.
Bạn thử tạm chỉnh như sau. Xin lỗi tôi chưa test
...........
strValueList = strValueList & strControlName & ","
End If
Next
strValueList = Left(strValueList, Len(strValueList) - 1)
...........
www.giaiphapexcel.com/diendan/threads/gi%C3%BAp-l%E1%BB%97i-run-time-error-3075-c%E1%BB%A7a-c%C3%A2u-l%E1%BB%87nh-sql-khi-t%E1%BA%A1o-report-theo-checkboxes.96616/
Khóa học Power PI – Ứng dung trong Nhân sự
TỔNG QUAN KHÓA HỌC: POWER BI CHO NGÀNH NHÂN SỰ Khóa học Power BI cho Nhân sự được thiết kế dành riêng cho các...
Xem khóa học