Home > Software engineering >  TXT import ACCESS
TXT import ACCESS

Time:10-06

Text format
"11", "22", "33",
"11", "22", "33",
"11", "22", "33",

SQL
Private Sub Command2_Click ()
Dim ag As String
With CommonDialog2
CommonDialog2. Filter="Text/*.txt | *. TXT"
CommonDialog2. ShowOpen
Ag=CommonDialog2. FileName
Text2. Text=ag
End With
If ag="" Then
The Exit Sub
End the If
Conn3. Execute (" delete from [ztry] ")
If Rst. State & lt;> AdStateClosed Then Rst. Close
Rst. Open the "select * from PM", Conn3, adOpenKeyset, adLockBatchOptimistic
The Open ag For Input As # 1
Do Until EOF (1)
Input # 1, N1, and N2 and N3
'
writing databaseStrSQL="INSERT into PM (field 1, 2, and field 3) values (" & amp; "'" & amp; N1 & amp; "'," & amp; "'" & amp; N2 & amp; "'," & amp; "'" & amp; N3 & amp; "'" & amp;
")"Conn3. Execute strSQL
Loop
MsgBox "at the end of input," vbInformation, "data entry"
Close # 1
End Sub
have a comma in the text, can not import, warrior, please modify! to see the line input, but can't write code

CodePudding user response:

Don't need to write programs that directly in the access to CSV format can be imported,

CodePudding user response:

If is a comma "of" standard text format, it can be as a Jet Engine to import external database,

In fact, even with your import line by line, this method is feasible,
 
N (Dim) As String, TMP As String

Do Until EOF (1)
The Line Input # 1, TMP
N=Split (TMP, ", ")
If Ubound (N)=2 Then
'
writing databaseStrSQL="INSERT into PM (field 1, 2, and field 3) values (" & amp; "'" & amp; N (0) & amp; "'," & amp; "'" & amp; N (1) & amp; "'," & amp; "'" & amp; N (2) & amp; "'" & amp;
")"Conn3. Execute strSQL
End the If
Loop

  • Related