Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

text field being padded with blank...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Burke in Novi - 21 Nov 2006 15:44 GMT
I have two fields defined in a table, each as a text field with a length of
5. They are defined identically. I create a new record in a recordset using
.AddNew and assign values to these fields., then use .Update to write the new
record. I assign values to each field using a String variable. When the
variable has a length of four, one of the fields works as expected, but the
other one ends up with a blank or unprintable character at the end. I went
into debug mode and viewed the values. At the assignment statement the string
variable has a value of "2809", but after it is assigned to the table's text
field, the text field has a value of "2809 ". I can't for the life of me
figure out why this is happening. Any idea? Any help is appreciated! Thanks.

Jim Burke
Allen Browne - 21 Nov 2006 16:04 GMT
Sounds like one of 2 things is happening. Either
- The string is a fixed length (so it has a trailing character), or
- The field is a fixed length, so it is always 5 characters long.

If it is a fixed-length string, it will be declared like this:
   Dim MyString As String * 5
You can fix the problem by simply declaring:
   Dim MyString As String

A fixed-width field cannot be created through the Access table design
interface. The most common way to accidently create such a field is by
executing a DDL query using CHAR(50) instead of TEXT(50) to create the
field.

The simplest workaround using the interface might be to:
1. Open the table in design view.
2. Rename the problem field. Save.
3. Create a new field of type Text. Save.
4. Use an Update query to populate the new field with:
   Trim([MyOldField])
5. Delete the old field from the table after verifying the results.

An alternative approach using code (haven't tested this) might be:
   Dim strSql As String
   strSql = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(50);"
   DBEngine(0)(0).Execute strSql, dbFailOnError

Signature

Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

>I have two fields defined in a table, each as a text field with a length of
> 5. They are defined identically. I create a new record in a recordset
[quoted text clipped - 14 lines]
>
> Jim Burke
Jim Burke in Novi - 21 Nov 2006 16:19 GMT
You got it - I used DDL and CHAR(5). I was doing this way back when and
discovered the problem with using CHAR and changed my code that defines new
fields to use TEXT. But this field was defined before I made that change.
Thanks! That one was driving me nuts. I knew I had changed my definitions
from CHAR to TEXT but forgot that there were a couple of fields that had
already been created before that.

> Sounds like one of 2 things is happening. Either
> - The string is a fixed length (so it has a trailing character), or
[quoted text clipped - 41 lines]
> >
> > Jim Burke
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.