Re: How to ignore extra or missing columns?
- From: John Nurick <j.mapSoN.nurick@xxxxxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 06:54:05 +0000
This probably isn't difficult, but it's beyond the capability of the
standard text import mechanism.
The way you describe it, it sounds as if the first few columns define a
record, and the remaining columns contain a variable number of related
items. If so, the best approach would be to parse the CSV file
accordingly and import it into records in two or more related tables.
Otherwise, you can either pre-process the CSV files,to give them all the
desired number of fields, or else write VBA code to read them line by
line and append fields to the table as required.
This snippet of VB/VBA code will take a comma-delimited list of values
and return the first NFields of them, padding with empty values if there
aren't enough in the list. If you remove the As String, As Long, etc. it
will also work in VBScript.
Function Make20(Line As String, NFields As Long) As String
Dim arFields As Variant
arFields = Split(Line, ",", NFields + 1)
If UBound(arFields) <> NFields -1 Then
ReDim Preserve arFields(NFields -1)
End If
Split20 = Join(arFields, ",")
End Function
On 30 Jan 2006 19:40:38 -0800, "topmind" <topmind@xxxxxxxxxxxxxxxx>
wrote:
>I need a way to dynamically process input CSV files with varying
>schemas. I have not found a way to get Access to ignore extra or
>missing columns. For example, suppose I set up a work table with 30
>columns. Sometimes I want it to automatically import a 10-column table
>and other times a 50 column table. The first should simply have nulls
>in the extra 20 and the second one (50 cols) would have the last 20 be
>ignored. It is too picky about knowing the number of columns in
>advanced. I live in a dynamic world :-)
>
>Thanks in advanced for any solutions proposed.
>
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
.
- References:
- How to ignore extra or missing columns?
- From: topmind
- How to ignore extra or missing columns?
- Prev by Date: How to ignore extra or missing columns?
- Next by Date: link outlook messages to table in access
- Previous by thread: How to ignore extra or missing columns?
- Next by thread: link outlook messages to table in access
- Index(es):
Relevant Pages
|