Solved

Changing number type programmatically - urgent

Posted on 2000-02-13
7
127 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now