Solved

Changing number type programmatically - urgent

Posted on 2000-02-13
7
129 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 40
Notepad++ how to remove delimiter : from beggning of the line? 3 114
Hide vba in gp 7 106
Set email body to html using vbscript 6 49
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

821 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