Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 133
  • Last Modified:

Changing number type programmatically - urgent

I have a VB6 program that uses a Access database. A few of the field numbers are required to be changed from integer to single or double. As the program has been distibuted and has had large amounts of data entered how can I change these fields with an update program
0
leeuwin
Asked:
leeuwin
1 Solution
 
Erick37Commented:
"ACC: How to Change a Field's Data Type at Run Time with Code"

http://support.microsoft.com/support/kb/articles/Q128/0/16.asp
0
 
inprasCommented:
use ALTER TABLE for this
0
 
RuchiCommented:
This is from Q.10100419 in VB database.

From: Tougas
Title: "Changing a field's type (text,long,double...)"

Question -----
Is there any way to change a field's type.
I need to create a little application that will save me the use of ACCESS on
computer that don't have it, to update fields....I found a way to change the
name, but the type...
thanks in advance!!!

From: dm_14
           
Answer-----                          
1. Create a temporary table
2. Copy the structure of the original table except for the field whose type is to be modified
3. In the temporary table add the field to be modified with its new type
4. copy all data to temporary table (do the necessart conversion for the field
whose type has changed)
5. delete original table
6. rename the temporary table to the original table's name
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!

 
macuCommented:
To add to what Erick37 said use the following statement (filling in between the <>'s):

<DataBaseVar>.Execute "ALTER TABLE <TableName> ALTER COLUMN <ColumnName> SINGLE"

this will change <ColumnName>'s type to single.

The only thing to be careful with is that you don't change the data type to a smaller type, e.g. from single to integer, as you may lose data or get errors due to indexes. Changing from integer to single or double is fine. You can also set whether or not the column can store NULL data with this statement (add NULL or NOT NULL).
0
 
leeuwinAuthor Commented:
Thanks guys, Erick37 if like to post your comment as an answer I will give the points.
0
 
mcriderCommented:
Erick37 doesn't have to post... Just click on the "Accept Comment" hot-spot on his comment...


Cheers!
0
 
Erick37Commented:
Reposting as answer.
Thanks.

"ACC: How to Change a Field's Data Type at Run Time with Code"

http://support.microsoft.com/support/kb/articles/Q128/0/16.asp
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now