Hi, I'm trying to update only 2 columns (prod_desc & item_cat) of a temp table with data from a master table. But, I found my code updates all rows with the same prod_desc and item_cat, don't know where I'm doing wrong. PLease help.
Code:
Private Sub UpdateTempTbl()
Dim rs2, rs3 As New ADODB.Recordset
Dim sql2, sql3 As String
Dim updateOn As String
updateOn = System.DateTime.Now.ToString(("yyyy-MM-dd HH:mm:ss"))
Call ConnectDB()
sql2 = "Select * From inventory_temp"
rs2.Open(sql2, conndb, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
With rs2
Do While Not .EOF
If RecordExist(rs2.Fields("tag_no").Value) = True Then
Else
sql3 = "Select * from master_data"
rs3.Open(sql3, conndb, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
conndb.Execute("UPDATE inventory_temp set prod_desc='" & UCase(Trim(rs3.Fields("prod_desc").Value)) & _
"', item_cat='" & UCase(Trim(rs3.Fields("item_cat").Value)) & _
"', created_by='" & UCase(InvDataEntryForm.txtID.Text) & _
"', created_on='" & updateOn & _
"', last_update_by='" & UCase(InvDataEntryForm.txtID.Text) & _
"', last_update_on='" & updateOn & _
"', status='" & Trim(1) & _
"' where prod_code ='" & UCase(Trim(rs2.Fields("prod_code").Value)) & "' ")
rs3.Close()
End If
.MoveNext()
Loop
End With
MsgBox("Data update completed.")
rs2.Close()
conndb.Close()
End Sub