Solved

coverting column type using code

Posted on 2000-05-04
5
232 Views
Last Modified: 2006-11-17
Is there any way to change the column type at run time using code?  I have a floating point column that I can convert to a currency type in design mode, however I want to do it at run time.  I am going to email a system to several users, they are going to fill in some information and it is going to import some data.  When it is done importing, I want it to automatically change the column name so I don't have to go over and do it for them.....is this possible?
0
Comment
Question by:ShaunMarion
  • 3
5 Comments
 
LVL 10

Accepted Solution

by:
paasky earned 100 total points
ID: 2777145
Hello ShaunMarion,

It's not possible to alter table field type at runtime (if that was what you wanted). Only way to do that is that you create a temporary column in your table, then move data there, remove old field and rename temporary field to old field name. Quite complicated eh?

Why not create new column into your table or use conversion functions to modify data or if you just need to change the field name you can alias it to different name with query:

SELECT Tax As TaxCode,
       Amount as [Extended Amount]
FROM Table1;

Hope this helps,
Paasky
0
 
LVL 9

Expert Comment

by:BrianWren
ID: 2777755
Paasky is right.  To do this in code,

1) Create a new column,
2) Transfer the data with a query (the fastest way) or a loop,
3) Delete the original column,
4) Create a new column of the type you want the data to be,
5) Copy back the data,
6) Then delete the temp field.


It probably would be better to change the data type on the way into the table than to get the data into the table then change it...

Brian
0
 
LVL 10

Expert Comment

by:paasky
ID: 2777835
Here's the link to PAQ where you'll find code which uses above method to modify field type in runtime:

http://www1.experts-exchange.com/bin/Q.10325861

Paasky
0
 
LVL 30

Expert Comment

by:hnasr
ID: 2778853
Why do you want to change the column type in the table?

What about using a query to change the type of the required field.

You may create the query using code, using the querydef object.



dim myq as queryDef
set myq = CurrentDb.CreateQueryDef("query_1", "select CCur(ty.y1) as y1, ty.y2

query_1 can be set as the record source for a form or a report!

0
 
LVL 10

Expert Comment

by:paasky
ID: 2793790
Glad I was able to help you ShaunMarion. Good luck to your project!

Best regards,
paasky
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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

948 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

21 Experts available now in Live!

Get 1:1 Help Now