tags:

views:

1067

answers:

7

I have a table in Access 2003 VBA with 164 columns but the data I get has 181 column and it is possible that it will get bigger in the future. I need to know how to resize my table an to add extra colums during the runtime I know how to check how many colums I need so I just need to know how to resize my own table.

thanks

+1  A: 

Might be something here. I'd probably create a new table based on the old one, and with the extra columns from data source. Then I'd populate the new table from the two data sources. I'd do this if for no other reason than it means I keep the old data safe while making the new.

boost
+3  A: 

Another option; rather than have a "short-fat" table with lots of columns, have a "tall-skinny" table with lots of rows:

Short-fat:

   ID
   FirstName
   LastName
   ...
   Amount

   1 Joe Smith   ... $123
   2 Bob Roberts ... $214
   3 Jim Black   ... $500

Tall-skinny:

   RecordID
   FieldNumber
   FieldName
   FieldValue

   1 1 FirstName Joe
   1 2 LastName  Smith
   ...
   1 n Amount $123
   2 1 FirstName Bob
   2 2 Lastname  Roberts
   ...
   2 n Amount    $214
   3 1 FirstName Jim
   3 2 LastName  Black
   ...
   3 n Amount    $500

This is good if you have a "stand alone" table that doesn't have to join with other tables, otherwise you're in for a world of pain.

Patrick Cuff
We use the tall skinny approach to represent product data from various vendors (I.e. Variable records from different vendors often delivered in some delimited format). Joins are fun but with a couple of extra date columns we can also support bitemporal queries.
pjp
+3  A: 

There is not much to base this on, but it sounds like a design problem. I would look at the data that is driving these additional columns and see if you can create a column to store it.

If the data is really that volatile, i would consider creating a new table with Key, FieldName, FieldValue as your columns. This way you wont have to change your reports, queries, import routines every time the data changes.

Mark Nold
+2  A: 

I don't have the reputation to comment, but to extend the short-fat vs long-skinny argument, i think its a good idea to start there. then you can create a crosstab query using the field that has the old field names as the column header. then write a make-table off of that query and you will have your table.

wakingrufus
I forgot about the crosstab query; that's a good idea :)
Patrick Cuff
A: 

the problem is that i don't have the rights to change the design the complete database is already created my job is just to impiment the reading of csv data but these dam... data need more colums than there were implimented by the previos programmer thats why i can't just delete the table and besides there are about 30 or 40 tables like the one i describet in the question thats why i asked for some kind of algorithm to change the amount of columns

but thanks for the fast awnser

@derdonn85 ... i'm not sure why changing the design via VBA is different to just changing the design. In reality it is not different at all. What you are trying to do is a going to make a lot of trouble for you in the future. If you are determined then @Remou's answer looks OK.
Mark Nold
+1  A: 

If you are stuck with this poor design, you can use SQL to add columns as you need them:

strSQL="ALTER TABLE tblTable ADD COLUMN NewCol Text (25)"
CurrentDB.Execute strSQL,dbFailOnError

Or you can use the TableDef.

Remou
Well, until the point you hit the 255-column limit for the table. Normalize the data NOW so you don't end up with an awful mess later, or a bunch of horrid workarounds in the interim.
David-W-Fenton
A: 

So are you looking for VB/VBA code to alter the table in the MDB? It sounds like that's what you're after -- something automated based on the incoming data. If you don't have permissions on the MDB file that's going to be hard to do, but I think what you're really saying is that you don't have the option to open the MDB in Access and modify it.

John Mo