xyhecho
01-13-2007, 07:52 PM
hello every one in excel i have very much record to import to access,how can i cortrol not to import duplicate record before updata?
Sub newadd()
Dim CNN As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim pthStr As String
Dim SQL As String
Dim ws As Worksheet
Dim i As Long
B1 = [a65536].End(xlUp).Row
pthStr = "C:\Documents and Settings\xyh\11\aa.mdb"
CNN.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & pthStr
SQL = "select * from talbe1"
RS.Open SQL, CNN, adOpenKeyset, adLockOptimistic, adCmdText
For i = 2 To B1
If Range("B" & i).Value <> "" Then
RS.AddNew
RS.Fields("period").Value = IIf(Range("A" & i).Value = "", Null, Range("A" & i).Value)
RS.Fields("cus").Value = IIf(Range("B" & i).Value = "", Null, Range("B" & i).Value)
RS.Fields("producer").Value = IIf(Range("C" & i).Value = "", Null, Range("C" & i).Value)
RS.Fields("sale").Value = IIf(Range("D" & i).Value = "", Null, Range("D" & i).Value)
RS.Update
End If
Next i
Set RS = Nothing
CNN.Close
End Sub
Sub newadd()
Dim CNN As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim pthStr As String
Dim SQL As String
Dim ws As Worksheet
Dim i As Long
B1 = [a65536].End(xlUp).Row
pthStr = "C:\Documents and Settings\xyh\11\aa.mdb"
CNN.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & pthStr
SQL = "select * from talbe1"
RS.Open SQL, CNN, adOpenKeyset, adLockOptimistic, adCmdText
For i = 2 To B1
If Range("B" & i).Value <> "" Then
RS.AddNew
RS.Fields("period").Value = IIf(Range("A" & i).Value = "", Null, Range("A" & i).Value)
RS.Fields("cus").Value = IIf(Range("B" & i).Value = "", Null, Range("B" & i).Value)
RS.Fields("producer").Value = IIf(Range("C" & i).Value = "", Null, Range("C" & i).Value)
RS.Fields("sale").Value = IIf(Range("D" & i).Value = "", Null, Range("D" & i).Value)
RS.Update
End If
Next i
Set RS = Nothing
CNN.Close
End Sub