李志能 发表于:2014-05-25 14:27:21
Open "D:\111.txt" For Input As #1
For i = 0 To 11
Input #1, ddd(i)
Debug.Print ddd(i) '这里显示的结果是正确的
Next
CurrentDb.Execute "INSERT INTO tblZhiJu Engineering, WorkDate,CeLiangYuan1,CeLiangYuan2,JiLuYuan,ZuoTuYuan,XA,[yA],[zA],[Xb],[yb],[zb] " & _
"VALUES (ddd(0),ddd(1),ddd(2),ddd(3),ddd(4),ddd(5),ddd(6),ddd(7),ddd(8),ddd(9),ddd(10),ddd(11))"
Do Until EOF(1)
For i = 0 To 5
Input #1, ddd(i)
Debug.Print ddd(i) '这里显示的结果是正确的
Next
CurrentDb.Execute "INSERT INTO tblZhiJuDetailed ZhiJuID, ZhuChi,BiaoJi,ChiZuo,ChiYou,ChiShang,ChiXia " & _
"VALUES (ddd(0),ddd(1),ddd(2),ddd(3),ddd(4),ddd(5))"
Loop
【Access源码示例】-导入导出系列-根据SQL语句导出数据到txt记事本[Access软件网]
http://www.accessoft.com/article-show.asp?id=7360
Private Sub cmdDRYSJL_Click()
Dim strSourceFile As String
Dim strPath, strpath1 As String
Dim strLine As String
Dim intBkp, intID As Integer
Dim intYear, intMonth As Integer
Dim strSQL As String
Dim cnn As Object 'ADODB.Connection
Dim rst As Object 'ADODB.Recordset
Dim i, j As Integer
Dim ddd(11) As Variant
strPath = "\\Mlks23\技术股\支距测量记录\DAT"
On Error Resume Next
' MkDir strdir '创建文件夹
' 现在查找存在的TXT文件
For intYear = 1900 To Year(Now())
For intMonth = 1 To 12
strpath1 = strPath & "\" & intYear & "-" & Format(intMonth, "00")
' MsgBox strPath
Debug.Print strpath1
strSourceFile = Dir(strpath1 & "\*.txt")
Do While Len(strSourceFile) > 0
intBkp = intBkp + 1
Debug.Print strpath1 & "\" & strSourceFile
Open strpath1 & "\" & strSourceFile For Input As #1
For i = 0 To 11
Input #1, ddd(i)
Debug.Print ddd(i)
Next
Set cnn = CurrentProject.Connection
strSQL = "SELECT * FROM [tblZhiJu]"
Set rst = OpenADORecordset(strSQL, adLockOptimistic, cnn)
rst.AddNew
rst![Engineering] = CStr(ddd(0))
rst![WorkDate] = CDate(ddd(1))
rst![CeLiangYuan1] = CStr(ddd(2))
rst![CeLiangYuan2] = CStr(ddd(3))
rst![JiLuYuan] = CStr(ddd(4))
rst![ZuoTuYuan] = CStr(ddd(5))
rst![XA] = CSng(ddd(6))
rst![YA] = CSng(ddd(7))
rst![ZA] = CSng(ddd(8))
rst![XB] = CSng(ddd(9))
rst![YB] = CSng(ddd(10))
rst![ZB] = CSng(ddd(11))
rst.Update
intID = rst![ZhiJuID]
rst.Close
Do Until EOF(1)
For i = 0 To 5
Input #1, ddd(i)
Debug.Print ddd(i)
Next
strSQL = "SELECT * FROM [tblZhiJuDetailed]"
Set rst = OpenADORecordset(strSQL, adLockOptimistic, cnn)
rst.AddNew
rst![ZhiJuID] = intID
rst![ZhuChi] = CSng(ddd(0))
rst![BiaoJi] = CStr(ddd(1))
rst![ChiZuo] = CSng(ddd(2))
rst![ChiYou] = CSng(ddd(3))
rst![ChiShang] = CSng(ddd(4))
rst![ChiXia] = CSng(ddd(5))
rst.Update
rst.Close
Loop
Close #1
' 获取下一个文件
strSourceFile = Dir
Loop
Next
Next
MsgBox "共导入完成 " & intBkp & " 个文件!"
End Sub
搞定了!900多个文件,5分钟才导入完成!
总记录:2篇 页次:1/1 9 1 :