|
Private Sub Command0_Click()
'=====================导入数据
DoCmd.SetWarnings False
If ExistTable("t_TmpSUP") = True Then
DoCmd.RunSQL "delete * from t_TmpSUP"
End If
Dim ss, ss1, tempstr, iline, aa, txetname
ss = ""
txetname = Me.TxetA
aa = CurrentProject.Path & "\" & txetname & ".txt"
Open aa For Input As #1
iline = 0
Do While Not EOF(1)
Line Input #1, tempstr
tempstr = Trim(Mid(tempstr, 1, 20)) & "," & Trim(Mid(tempstr, 21, 22)) & "," & Trim(Mid(tempstr, 34))
ss = ss & tempstr & vbCrLf
iline = iline + 1
Loop
Close #1
Open CurrentProject.Path & "\abc.txt" For Output As #2
Print #2, ss
Close #2
DoCmd.TransferText acImportDelim, "me", "t_TmpSUP", CurrentProject.Path & "\abc.txt", False
If Dir(CurrentProject.Path & "\abc.txt") <> "" Then
Kill CurrentProject.Path & "\abc.txt"
End If
'=====================追加数据
DoCmd.RunSQL "delete * from t_SUP where SUP in (select SUP from t_TmpSUP);", False
DoCmd.RunSQL "INSERT INTO t_SUP SELECT * FROM t_TmpSUP;", False
DoCmd.SetWarnings True
End Sub
Private Function ExistTable(strTableName As String) As Integer
Dim i As Integer
ExistTable = False
For i = 0 To CurrentData.AllTables.Count - 1
If strTableName = CurrentData.AllTables(i).Name Then
ExistTable = True
Exit For
End If
Next i
End Function |
|