怎样修改如下代码把 <文本1> 导入数据库private Sub drsj_Click()
Dim File_Gz As String
Dim yf As String
Dim i As Long
Dim a As Long
Dim b As Long
Dim str As String
Dim str1 As String
Dim str2 As String
Dim tmp_bh As String
Dim Tmp_rq As String
Dim Tmp_hq As String
Dim Tmp_sy As String
Dim Tmp_ly As String
Dim Tmp_yn As String
Dim Tmp_en As String
Dim Tmp_sn As String
Dim Tmp_wn As String
Dim Tmp_bn As String
Dim Tmp_fh As String
Dim mText As String
Dim CH As String * 1
On Error GoTo err
ComDiaGz.Filter = "TXT Files(*.txt)|*.txt"
ComDiaGz.FilterIndex = 1
ComDiaGz.ShowOpen
File_Gz = ComDiaGz.FileName
If File_Gz = "" Then Exit Sub
Open File_Gz For Input As #1
tsql = "delete from db3"
dbsModb.Execute tsql
Set Rst = dbsModb.OpenRecordset("db3")
yf = InputBox$("请输入要导入数据的月份(如:06,12。)", "输入提示")
Do While Not EOF(1)
yyy: For b = 1 To 23
If EOF(1) = True Then
Rst.Close
Close #1
bb = MsgBox("数据读入完毕", vbInformation, "读盘")
frmDrsj.Show
Exit Sub
End If
Line Input #1, mText
str1 = ""
str1 = Mid(mText, 6, 2)
str2 = Mid(mText, 14, 2)
If str1 <> yf Or str2 = "99" Then
GoTo yyy
End If
i = 0
a = 0
CH = ""
str = ""
Do While i < Len(mText)
i = i + 1
CH = Mid(mText, i, 1)
If CH <> "|" Then
str = str + CH
Else
If a = 0 Then Tmp_rq = str
If a = 1 Then tmp_bh = str
If a = 2 Then Tmp_fh = str
If a = 3 Then
Select Case Tmp_fh
Case "211101"
Tmp_hq = str
Case "215103"
Tmp_sy = str
Case "215106"
Tmp_ly = str
Case "215121"
Tmp_yn = str
Case "215122"
Tmp_en = str
Case "215123"
Tmp_sn = str
Case "215125"
Tmp_wn = str
Case "215128"
Tmp_bn = str
Case Else
aa = 1
End Select
End If
str = ""
a = a + 1
End If
Loop
Next b
With Rst
.AddNew
!bh = tmp_bh
!rq = Tmp_rq
!hq = Tmp_hq
!sy = Tmp_sy
!ly = Tmp_ly
!yn = Tmp_yn
!en = Tmp_en
!sn = Tmp_sn
!wn = Tmp_wn
!bn = Tmp_bn
.Update
End With
Loop
Rst.Close
Close #1
i = MsgBox("数据读入完毕", vbInformation, "读盘")
frmDrsj.Show
Exit Sub
err:
i = MsgBox("数据读入错误", vbInformation, "读盘")
frmMain.sxfjs = False
End Sub
谢谢!!!!!!!!作者: lichun 时间: 2004-3-27 05:54
有那么复杂吗?要学用的办法就是直接引到XLS,再转换到ACCESS里就行了作者: jqlscsl 时间: 2004-4-5 01:39