I have a field that has anywhere from 0 to 5 entries, that are
separated by a comma. I'd like to put them into (up to) 5 separate
fields. Each entry is the same length, 10 characters (plus the
comma).
Would that be:
0123456789, 0123456789, 0123456789, 0123456789, 0123456789
or:
0123456789,0123456789,0123456789,0123456789,0123456789
If your destination fields are Field1, Field2, etc. (any names will
do):
INSERT INTO tblSplit ( Field1, Field2, Field3, Field4, Field5 )
SELECT Left([Text],10), Mid([Text],13,10), Mid([Text],25,10),
Mid([Text],37,10), Mid([Text],49,10)
FROM tblSplit
WHERE tblSplit.Text Is Not Null;
Adjust the first numeric argument of Mid() if you don't have spaces
after the columns.
But, of course, you really don't want to do this. Instead, you want
to put the data in a separate table that links to the table with the
field with the comma-separated list.
This can also be done without having a fixed-length, using InStr()
to find the location of the first comma and using that as the length
of what you return. But that results in such complex SQL that it's
usually a lot easier to write VBA code to do the job.