Hi, Peter,
Thanks for your help. I actually have the following codes in an excel spreadsheet from which I read unit info and update the tblUnit table in Access if there are any differences. And I do have "Option Explicit" at the top of my module
I did what you suggested, the results are as following,
Code:
AAA,243
UPDATE tblUnit SET Unit_Name ='' WHERE CC =''
The routines are as below,
Code:
Private Sub
btnUpdateUnitInfoInDB_Click()
Dim strSQL As String
Dim strCC As String, strUName As String
Dim i As Long
strSQL = "UPDATE tblUnit SET Unit_Name ='" & strUName & "' WHERE CC ='" & strCC & "'"
Call OpenCN
On Error GoTo ErrHander
For i = 2 To 116
strUName = Me.Range("B" & i).Value
strCC = Me.Range("A" & i).Value
Debug.Print strUName & "," & strCC
cn.Execute strSQL
Debug.Print strSQL
Next i
Call CloseCN
Exit Sub
ErrHander:
MsgBox "Error!"
Call CloseCN
End Sub