Office中国论坛/Access中国论坛

标题: 如何把 [打印本页]

作者: jqlscsl    时间: 2004-3-27 05:46
标题: 如何把
=======文本1============
0501|2004-01-01|1569.78|211102|
0501|2004-01-03|69326.22|215103|
0501|2004-01-03|6398.66|215121|
0502|2004-01-01|6398.20|211102|
0502|2004-01-02|6309.59|215121|
0502|2004-01-03|63521.01|215123|
0502|2004-01-03|12634.55|215122|
0503|2004-01-01|6623.22|211102|
0503|2004-01-06|5654.11|215125|
0503|2004-01-11|6941.21|215128|
0503|2004-01-15|6312.24|215121|
其中<211102为 活期> <215103 为三月><215106为六月><215121为一年>
<215122为二年><215123为三年><215125为五年><215128为 八年>
==========================
数据库为data.mdb其中表名为db3
结构为 bh--zdm--rq--hq--sy--ly--yn--en--sn--wn--bn
意思为:编号--站代码-日期--活期--三月--六月--一年--二年---三年---五年--八年

怎样修改如下代码把 <文本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


     程序运行不了
                      请帮忙看看!!!
                   谢谢!!!
                                          
作者: ququ    时间: 2004-4-5 01:51
直接用宏解决问题
作者: 土豆    时间: 2004-4-5 17:55
DoCmd.TransferText , , "TableName", "TextFileName"

作者: jqlscsl    时间: 2004-4-5 21:21


不明白,给段代码吧!!!
作者: 土豆    时间: 2004-4-5 21:26
DoCmd.TransferText , , "TableName", "TextFileName"
这不是代码么?

用ACCESS的帮助找TransferText




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3