add 2 leading spaces to text files

Dave_epic

Registered User.
Local time
Today, 03:28
Joined
Mar 6, 2008
Messages
39
Hi

I wonder if anyone can help me.
I have a bunch of CSV text files (over 400) and want to add 2 leading spaces to the beginning of each row. So the rows would go from this to this. (quotation marks are only for format purposes)


"00??,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,C,11,59,0,6,4,4,6,6,4,5,6,5,20090319"


" 00??,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,C,11,59,0,6,4,4,6,6,4,5,6,5,20090319"


My VBA skills are not as good as SQL skills. I was thinking that to do this I would have to use the run sql command using this sql code on the first field. Right((" " & [field1]),6). This adds leading zeros to the first field in access.

But then using this method I would have to import each text file into fixed width text format on a loop and then run the sql code on it.

Is this a useful method or does anyone know of a better method.

Thanks
 
Last edited:
Look up the "Open" / input / Print/ Write / Close commands
You can open the textfile, input/read then print line by line adding in spaces where needed.
 
Hi

I wonder if anyone can help me.
I have a bunch of CSV text files (over 400) and want to add 2 leading spaces to the beginning of each row. So the rows would go from this to this. (quotation marks are only for format purposes)


"00??,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,C,11,59,0,6,4,4,6,6,4,5,6,5,20090319"


" 00??,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,C,11,59,0,6,4,4,6,6,4,5,6,5,20090319"


My VBA skills are not as good as SQL skills. I was thinking that to do this I would have to use the run sql command using this sql code on the first field. Right((" " & [field1]),6). This adds leading zeros to the first field in access.

The Right function only selects "x" number of characters from the right side of a string. So in that example - you're telling it to select the last 6 characters from the string: " " & [field1]...which is only 6 characters long to begin with.

You could achieve the same thing with just: " " & [field1]

Either: SELECT " " & [field1] AS YourFieldName FROM YourTableName

Or: UPDATE YourTableName SET YourTableName.field1 = " " & [field1]

You don't need to use the Right function.

Is this a one time kind of thing, or will you have to do it on a recurring basis?

What is the end goal?
 
The first field to be imported 00?? would become ^^00?? (^ means space).

Why do you want a field to have leading spaces? does it serve a purpose?

David
 

Users who are viewing this thread

Back
Top Bottom