Dear Everyone,
Pls see and how to fix error sub c1tim() on command 4 of form as follows:
Sub c1tim(tablea As String, loai As String, x1 As Integer, tableb As String)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim i As Integer
' Bu?c 1: Tìm giá tr? x1 trong các c?t C1 d?n C6 c?a tablea
Set db = CurrentDb()
strSQL = "SELECT * FROM " & tablea & " WHERE Type = '" & loai & "'"
Set rs = db.OpenRecordset(strSQL)
' Bu?c 2: Xóa d? li?u tableb tru?c khi dùng SQL vi?t các giá tr? tìm du?c ? bc1 vào tableb
strSQL = "DELETE * FROM " & tableb
db.Execute strSQL, dbFailOnError
' Bu?c 3: Sao chép toàn b? dòng tìm th?y t? tablea vào tableb
While Not rs.EOF
For i = 1 To 7
If rs.Fields("C" & i) = x1 Then
strSQL = "INSERT INTO " & tableb & " SELECT * FROM " & tablea & " WHERE C" & i & " = " & x1 & " AND Type = '" & loai & "'"
db.Execute strSQL, dbFailOnError
Exit For
End If
Next i
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
The sub to update data into table "daso455"
Although query1 is ok.
Pls find the attachment for your ref., thanks.
Thanks& Regards,
Btamsgn
Pls see and how to fix error sub c1tim() on command 4 of form as follows:
Sub c1tim(tablea As String, loai As String, x1 As Integer, tableb As String)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim i As Integer
' Bu?c 1: Tìm giá tr? x1 trong các c?t C1 d?n C6 c?a tablea
Set db = CurrentDb()
strSQL = "SELECT * FROM " & tablea & " WHERE Type = '" & loai & "'"
Set rs = db.OpenRecordset(strSQL)
' Bu?c 2: Xóa d? li?u tableb tru?c khi dùng SQL vi?t các giá tr? tìm du?c ? bc1 vào tableb
strSQL = "DELETE * FROM " & tableb
db.Execute strSQL, dbFailOnError
' Bu?c 3: Sao chép toàn b? dòng tìm th?y t? tablea vào tableb
While Not rs.EOF
For i = 1 To 7
If rs.Fields("C" & i) = x1 Then
strSQL = "INSERT INTO " & tableb & " SELECT * FROM " & tablea & " WHERE C" & i & " = " & x1 & " AND Type = '" & loai & "'"
db.Execute strSQL, dbFailOnError
Exit For
End If
Next i
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
The sub to update data into table "daso455"
Although query1 is ok.
Pls find the attachment for your ref., thanks.
Thanks& Regards,
Btamsgn
Last edited: