Solved

Change Field Size through VB

Posted on 2002-07-01
7
204 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
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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

713 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