vb6如何把excel数据导入access指定的表内?
发布网友
发布时间:2022-05-01 11:57
我来回答
共1个回答
热心网友
时间:2023-10-10 23:01
Option Explicit
Public Db As DAO.DatabasePublic DbAcc As DAO.Database
Private Function S_GetData() As Boolean
Dim rd As DAO.Recordset
Dim rdacc As DAO.Recordset
Dim i As Integer
Dim lRow As Long
Dim sSQL As String
Dim sXLSPath As String
Dim sMDBPath As String
Dim bErr As Boolean
S_GetData = False
Screen.MousePointer = 11
sXLSPath = App.Path & "\PH.XLS"
sMDBPath = App.Path & "\PH.MDB"
Set Db = OpenDatabase(sXLSPath, False, False, "Excel 8.0;")
Set DbAcc = OpenDatabase(sMDBPath)
Set rd = Db.OpenRecordset("sheet1$")
sSQL = "DELETE FROM TH"
DbAcc.Execute sSQL
sSQL = "SELECT * FROM TH"
Set rdacc = DbAcc.OpenRecordset(sSQL)
lRow = 0
For i = 1 To rd.RecordCount
If Trim(rd!区分) = "B" Or Trim(rd!区分) = "R" Then
rdacc.AddNew
rdacc.Fields("受付番号") = rd.Fields("受付番号")
rdacc.Fields("受付日") = rd.Fields("受付日")
rdacc.Fields("受付时间") = rd.Fields("受付时间")
rdacc.Fields("枚数") = rd.Fields("枚数")
rdacc.Fields("内訳") = rd.Fields("内訳")
rdacc.Fields("内容") = rd.Fields("内容")
rdacc.Fields("区分") = rd.Fields("区分")
rdacc.Fields("物件(栋)コード") = rd.Fields("物件(栋)コード")
rdacc.Fields("BUG数") = rd.Fields("BUG数")
If Trim(rd!区分) = "R" Then
rdacc.Fields("区画番号") = rd.Fields("区画番号")
Else
rdacc.Fields("区画番号") = " "
End If
rdacc.Fields("支払、请求区分") = rd.Fields("支払、请求区分")
rdacc.Fields("制作者") = rd.Fields("制作者")
rdacc.Fields("校正者") = rd.Fields("校正者")
rdacc.Fields("最终校正UP") = rd.Fields("最终校正UP")
rdacc.Fields("时间") = rd.Fields("时间")
rdacc.Fields("校正KB") = rd.Fields("校正済")
rdacc.Fields("纳品区分") = rd.Fields("纳品区分")
rdacc.Fields("Update") = rd.Fields("Update")
rdacc.Fields("番号") = i + 1
rdacc.Update
End If
rd.MoveNext
Next
rd.Close: Set rd = Nothing
rdacc.Close: Set rdacc = Nothing
Db.Close: Set Db = Nothing
End Function
Private Sub Command1_Click()
S_GetData
End Sub
去我资料里有我网盘的地址 去找excel to access.rar这个文件!~这个是源程序
热心网友
时间:2023-10-10 23:01
Option Explicit
Public Db As DAO.DatabasePublic DbAcc As DAO.Database
Private Function S_GetData() As Boolean
Dim rd As DAO.Recordset
Dim rdacc As DAO.Recordset
Dim i As Integer
Dim lRow As Long
Dim sSQL As String
Dim sXLSPath As String
Dim sMDBPath As String
Dim bErr As Boolean
S_GetData = False
Screen.MousePointer = 11
sXLSPath = App.Path & "\PH.XLS"
sMDBPath = App.Path & "\PH.MDB"
Set Db = OpenDatabase(sXLSPath, False, False, "Excel 8.0;")
Set DbAcc = OpenDatabase(sMDBPath)
Set rd = Db.OpenRecordset("sheet1$")
sSQL = "DELETE FROM TH"
DbAcc.Execute sSQL
sSQL = "SELECT * FROM TH"
Set rdacc = DbAcc.OpenRecordset(sSQL)
lRow = 0
For i = 1 To rd.RecordCount
If Trim(rd!区分) = "B" Or Trim(rd!区分) = "R" Then
rdacc.AddNew
rdacc.Fields("受付番号") = rd.Fields("受付番号")
rdacc.Fields("受付日") = rd.Fields("受付日")
rdacc.Fields("受付时间") = rd.Fields("受付时间")
rdacc.Fields("枚数") = rd.Fields("枚数")
rdacc.Fields("内訳") = rd.Fields("内訳")
rdacc.Fields("内容") = rd.Fields("内容")
rdacc.Fields("区分") = rd.Fields("区分")
rdacc.Fields("物件(栋)コード") = rd.Fields("物件(栋)コード")
rdacc.Fields("BUG数") = rd.Fields("BUG数")
If Trim(rd!区分) = "R" Then
rdacc.Fields("区画番号") = rd.Fields("区画番号")
Else
rdacc.Fields("区画番号") = " "
End If
rdacc.Fields("支払、请求区分") = rd.Fields("支払、请求区分")
rdacc.Fields("制作者") = rd.Fields("制作者")
rdacc.Fields("校正者") = rd.Fields("校正者")
rdacc.Fields("最终校正UP") = rd.Fields("最终校正UP")
rdacc.Fields("时间") = rd.Fields("时间")
rdacc.Fields("校正KB") = rd.Fields("校正済")
rdacc.Fields("纳品区分") = rd.Fields("纳品区分")
rdacc.Fields("Update") = rd.Fields("Update")
rdacc.Fields("番号") = i + 1
rdacc.Update
End If
rd.MoveNext
Next
rd.Close: Set rd = Nothing
rdacc.Close: Set rdacc = Nothing
Db.Close: Set Db = Nothing
End Function
Private Sub Command1_Click()
S_GetData
End Sub
去我资料里有我网盘的地址 去找excel to access.rar这个文件!~这个是源程序