Solved

coverting column type using code

Posted on 2000-05-04
5
233 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

810 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