quzbsc01_20.rar(2007-12-25 21:49:30, Size: 966 B , Downloads: 7)
''这是做好的函数Public Function Form_frmDataInto(Optional FileName As String = "")
On Error GoTo Err:
Dim FileNum As Long
Dim Temp As String
Dim varName As Variant
Dim strTemp As String
Dim i As Long
Dim m As Long
Dim TempFields As Variant ''字段
Dim TempValues As Variant ''值
Dim Conn As ADODB.Connection
Set Conn = CurrentProject.Connection
Dim strSQL As String
Dim rst As New ADODB.Recordset
If Len(FileName) = 0 Then FileName = CurrentProject.Path & "\QUZBSC01_11.028"
If MsgBox("确认要导入吗?", vbQuestion + vbYesNo) = vbNo Then Exit Function
strSQL = "SELECT top 1 * FROM 028"
rst.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
Open FileName For Input As #
Line Input #1, Temp ' 读入一行数据并将其赋予某变量。
varName = Split(Temp, vbLf)
strTemp = ""
''获得字段
strTemp = varName(9)
TempFields = Split(strTemp, vbTab)
For i = 1 To UBound(TempFields)
Temp = TempFields(i)
Next
For i = 10 To UBound(varName) - 1
strTemp = varName(i)
TempValues = Split(strTemp, vbTab)
rst.AddNew
For m = 0 To UBound(TempFields)
rst(TempFields(m)) = TempValues(m)
rst.Update
Next
Close #1
rst.Close
Set rst = Nothing
Set Conn = Nothing
Err:
Debug.Print Err.Description
Close #1
Exit Function
end Function
end Function