Solved

Add trailing spaces to a field

Posted on 2008-06-12
6
723 Views
Last Modified: 2010-04-21
How to I add trailing sapces to a field that will be exported to a .csv file
0
Comment
Question by:morang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 44

Expert Comment

by:GRayL
ID: 21772583
You can only add trailing spaces using a query:

Update myTable set myFld = myFld & "   ";

three spaces for example
0
 

Author Comment

by:morang
ID: 21772600
will that work if the number of spaces is not the same for every record?
0
 
LVL 44

Accepted Solution

by:
GRayL earned 500 total points
ID: 21772648
If you have a length you want to create then

UPDATE myTable SET myFld = Trim(myFld) & Space(30 - Len(Trim(myFld)));
-----------------------------------------------------------------^-- length of field with trailing spaces

In no case can the actual trimmed field length exceed the length you set.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:morang
ID: 31466685
Thank you for your help
0
 

Expert Comment

by:bmoabc
ID: 21772743
rather than writing to the table, you can also create a query that adds the spaces dynamically.

- Create a new query
- Add all the fields that you'd like exported
- replace the field(s) where you need trailing spaces with
     myFld:table.myFld & space(number of spaces)
- export new query

That way you're never writing to your original data
0
 
LVL 44

Expert Comment

by:GRayL
ID: 21772806
morang:  What bmoabc makes a lot of sense. Rather than the update to your table turn the update into a normal select query and export the the query.

bmoabc:  morang had accepted a minute before your post arrived.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PowerPivot (or MS Access ) -- Opening & Closing Balance 21 56
Access vs Access runtime 6 63
Access Excel ADO SQL question 8 49
Handle Apostrophes in VBA SQL - Part 2 10 47
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question