-
SQL lỗi khi tham chiếu trường trong Forms
Phung Duc > 02-11-16, 11:43 AM
Chào các bạn
- Nhờ các bác Chuyên Gia trong hội sửa giúp minh CODE bên dưới, Báo lỗi ở SQL khi Chạy thủ tục,
- Mình muốn add tên Chuyền vào từng record theo nhóm thì Code như thế nào
Vi dụ: Nhóm G01 muốn add tên nhom là G01-001-002-003-004 vào các record ở cột TenNhomSX
Nhóm G02 muốn add tên nhom là G02-001-002-003-004 vào các record ở cột TenNhomSX
Public Sub SanXuat()
Dim rs_NhomSX As DAO.Recordset
Dim strSQL As String
Dim TuanSX As String
Dim NhomSX As String
Dim Nh As String
TuanSX = [Forms]![FormsSanXuat]![txtTuanSX]
NhomSX = [Forms]![FormsSanXuat]![txtNhomSX]
strSQL = "SELECT FROM NhomSX WHERE (((Tuan)='" & TuanSX & "') AND ((Nhom)='" & NhomSX & "'));"
Set rs_NhomSX = CurrentDb.OpenRecordset(strSQL)
Nh = ""
rs_NhomSX.MoveFirst
Do While Not rs_NhomSX.EOF
Chuyen = rs_NhomSX!Chuyen
TenNhom = rs_NhomSX!TenNhomSX
Nh = Nh & "-" & Right(Chuyen, 3)
rs_NhomSX.MoveNext
Loop
Debug.Print rs_NhomSX!Tuan, rs_NhomSX!Chuyen, "Nhom" & Nh
End Sub
https://drive.google.com/file/d/0Bx9f5ZA...sp=sharing
Thanks -
RE: SQL lỗi khi tham chiếu trường trong Forms
Minh Tiên > 02-11-16, 03:17 PM
Chào bạn !
Bạn thay code của bạn thành:
Chúc thành công./.Mã:Public Sub SanXuat()
Dim rs_NhomSX As DAO.Recordset
Dim strSQL As String
Dim TuanSX As String
Dim NhomSX As String
Dim Chuyen As String
Dim Tennhom As String
Dim Nh As String
TuanSX = [Forms]![FormsSanXuat]![txtTuanSX]
NhomSX = [Forms]![FormsSanXuat]![txtNhomSX]
strSQL = "SELECT NhomSX.* FROM NhomSX WHERE (((Tuan)='" & TuanSX & "') AND ((Nhom)='" & NhomSX & "')) Order by Chuyen;"
Set rs_NhomSX = CurrentDb.OpenRecordset(strSQL)
If rs_NhomSX.RecordCount > 0 Then
Nh = ""
rs_NhomSX.MoveFirst
Do While Not rs_NhomSX.EOF
Chuyen = Nz(rs_NhomSX!Chuyen)
Tennhom = Nz(rs_NhomSX!Nhom)
Nh = Nh & "-" & Right(Chuyen, 3)
rs_NhomSX.MoveNext
Loop
MsgBox Tennhom & Nh 'Thay bằng câu Update ghi vào cột TennhomSX
Else
msgbox "Khong có số liệu !"
End If
End Sub