Solved

coverting column type using code

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

830 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