Solved

Change Field Size through VB

Posted on 2002-07-01
7
197 Views
Last Modified: 2010-05-02
Can I increase the size of a Text data type Field in table (MS Access Database)?

e.g. Table Name is EMPLOYEE
    Field Name is Fname Text(20)

Through VB Code I want to make it 25 or greater.

how it is possible? pl. let me know.

0
Comment
Question by:hnd_ra
  • 3
  • 2
  • 2
7 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 7122507
Hi hnd_ra,

don't think it's possible. see what MSDN help says

ALTER TABLE table {ADD {COLUMN field type[(size)] [NOT NULL] [CONSTRAINT index] |
CONSTRAINT multifieldindex} |
DROP {COLUMN field I CONSTRAINT indexname} }

Using the ALTER TABLE statement, you can alter an existing table in several ways. You can:

Use ADD COLUMN to add a new field to the table.

Use ADD CONSTRAINT to add a multiple-field index.

Use DROP COLUMN to delete a field.

Use DROP CONSTRAINT to delete a multiple-field index.

if you still want to do it there's a small workaround through DAO

-Assume a field trans_type TEXT (20) whose size needs to be 30.
-Add a field trans_type_temp TEXT(30)
-UPDATE <Table> SET trans_type_temp = trans_type
-Delete the trans_type field.
-Add a field trans_type TEXT(30)
-UPDATE <Table> SET trans_type = trans_type_temp
-Delete the trans_type_temp field.

lot of work better make a new table and move the data

HAGD:O)Bruintje
0
 
LVL 4

Expert Comment

by:RichW
ID: 7122595
Dim cnn as ADODB.Connection
Set cnn = New ADODB.Connection
   With cnn
      .Provider = "Microsoft.Jet.OLEDB.4.0;"
      .Open "Data Source=C:\Path\YourDB.mdb;"
   End With

cnn.Execute "ALTER TABLE YOURTABLE ALTER [FName] VarChar(25)"

0
 
LVL 4

Accepted Solution

by:
RichW earned 20 total points
ID: 7122639
bruintje,

Sorry.  I started writing the comment, then walked away and came back.  Didn't know you already gave the same thing I entered.

Anyway, hnd_ra the line should read:

cnn.Execute "ALTER TABLE EMPLOYEE ALTER [FName] VarChar(25)"

Cheers,
RichW
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 44

Expert Comment

by:bruintje
ID: 7122655
no problem, just wondering why i didn't do it with ado, guess because i got no setup to test now ;)
0
 

Author Comment

by:hnd_ra
ID: 7122894
Thanks  RichW ,
   This is working fine.
I wnted to know ne more thing, if I have to chnage DatType e.g. from Text to Long, then what will be the syntex.

Pl. let me know.

Again a lot of thanks

0
 
LVL 4

Expert Comment

by:RichW
ID: 7122931
Thanks hnd_ra.

I believe the following will change it to Number (Long Integer) for Access:

cnn.Execute "ALTER TABLE EMPLOYEE ALTER [FName] Long "

Thanks again!
RichW
0
 

Author Comment

by:hnd_ra
ID: 7123002
Thanks RichW ,
     Yeahn its working fine. Actually earlier I also did like this one but by mistake there was a parenthesis ")" in my syntex.

Really u r great.........

Thanks a lot

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 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