Solved

Changing number type programmatically - urgent

Posted on 2000-02-13
7
128 Views
Last Modified: 2010-05-02
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
Comment
Question by:leeuwin
7 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2517468
"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
 
LVL 4

Expert Comment

by:inpras
ID: 2517657
use ALTER TABLE for this
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2517683
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 1

Expert Comment

by:macu
ID: 2518187
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
 

Author Comment

by:leeuwin
ID: 2518296
Thanks guys, Erick37 if like to post your comment as an answer I will give the points.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2519425
Erick37 doesn't have to post... Just click on the "Accept Comment" hot-spot on his comment...


Cheers!
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 300 total points
ID: 2520713
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

777 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