导入代码:
Private Sub Command11_Click()
Dim conn
Dim conn2
Dim a As String
With CommonDialog1
.Filter = "EXCEL文件[*.XLS]|*.xls"
.ShowOpen
a = .FileName
Text2.Text = a
End With
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Persist Security Info=False;Data Source=" & App.Path + "\database.mdb " & ""
Set conn2 = CreateObject("ADODB.Connection")
conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties='Excel 8.0;HDR=Yes;IMEX=1';Data Source=" & Text2.Text & ""
SQL = "SELECT * FROM [Sheet1$]"
Set rs = conn2.Execute(SQL)
While Not rs.EOF
SQL = "insert into 合同管理表 ([姓名],[性别],[部门],[签订时间],[签订次数],[合同期限]) values('" & fixsql(rs(0)) & "','" & fixsql(rs(1)) & "','" & fixsql(rs(2)) & "','" & fixsql(rs(3)) & "','" & fixsql(rs(4)) & "','" & fixsql(rs(5)) & "')"
conn.Execute (SQL)
rs.MoveNext
Wend
conn.Close
Set conn = Nothing
conn2.Close
Set conn2 = Nothing
Adodc1.Refresh
DataGrid1.Refresh
End Sub
Function fixsql(str)
Dim newstr
newstr = str
If IsNull(newstr) Then
newstr = ""
Else
newstr = Replace(newstr, "'", "''")
End If
fixsql = newstr
End Function
请高手帮忙提供一下代码,将万分感谢(字段工号,日期都相同方可认定为重复数据)