Solved

Changing number type programmatically - urgent

Posted on 2000-02-13
7
126 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now