Home > Software engineering >  Vb text files, Excel import access, respectively
Vb text files, Excel import access, respectively

Time:10-06

Connect to the database
 Private Sub Form_Load () 
Dim cn As New ADODB. Connection
Dim the rs As New ADODB. You
Cn. The Open ". The Provider=Microsoft Jet. The OLEDB. 4.0; Data Source="& amp; App. The Path & amp; "\ ZTGXRBD. MDB; The Jet OLEDB: Database Password=; Admin, "
End Sub


TXT text file, Excel import access library where M respectively, table N the code, a lot of online directory file is fixed, fixed file import, but rookie to respectively through browse the file (not fixed path), any file names respectively file import access,
1, through the button to delete table M data first, and then realize the TXT import ACCESS table M, TXT format for a number of fields of space-delimited data (about 10 more fields listed),
2, through the button to delete C data table first, and then the implementation will EXCEL import ACCESS table in C, EXCLE have 3 field data,
Pursuing big cafe to write the code,

CodePudding user response:

1 used VB Jet Engine (usually used in the database Engine) was originally support text file as an external database, but it is under the condition of the default limit:
* records in the text file space, with a newline fields to commas;
* and the number of fields in a text file, the data type should match the Access to import table (at least the field number cannot exceed);
* the extension of a text file is restricted to several, does not support any filename, of course, this can bypass, that is to rename the temporary file

2. The Excel is a Jet Engine supported by external database,

Don't know why, the original poster to import the same table M the field number will change?

Finally, using the external database import, it is best to cn based on external database connection object,