vb6如何把excel数据导入access指定的表内?
1个回答
展开全部
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这个文件!~这个是源程序
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这个文件!~这个是源程序
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |