473,421 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Changing Stubborn Data Type

Hi Y'all I was hoping someone out there might be able to help me.

I have an access program that needs to change the data types
programatically. I have tried to do an alter column to change the
original data type from binary to text, but that did not work. The
current section of code I have is the following:

Public Function ChangeColumnType(ByVal StrgTableName As String, _
strgColumnName As String, StrgNewDataType) As Boolean

On Error GoTo Err_ChangeColumnType

DoCmd.RunSQL "ALTER TABLE [" & StrgTableName & "] ADD COLUMN [" &
strgColumnName & "-NEW] " & StrgNewDataType
DoCmd.RunSQL "UPDATE [" & StrgTableName & "] SET [" &
strgColumnName & "-NEW] = [" & strgColumnName & "]"
DoCmd.RunSQL "ALTER TABLE [" & StrgTableName & "] DROP COLUMN [" &
strgColumnName & "]"
ChangeColumnType = RenameColumn(StrgTableName, strgColumnName &
"-NEW", strgColumnName)

Exit_ChangeColumnType:
Exit Function

Err_ChangeColumnType:
MsgBox "There was an Error while changing the Table Column [" &
strgColumnName & "] to [" & _
StrgNewDataType & "] within the Table named [" & StrgTableName & "]
" _
, vbCritical, "Column Retype Error"
GoTo Exit_ChangeColumnType
End Function
Unfortunately this does not work. For some reason it wont drop the old
attibute and rename the newly created attribute. Instead it errors
out. Anyone have some suggestions? I would appreciate any and all
help.
Thanks,
Erica

Nov 29 '05 #1
2 1426
Br
Er**********@gmail.com wrote:
Hi Y'all I was hoping someone out there might be able to help me.

I have an access program that needs to change the data types
programatically. I have tried to do an alter column to change the
original data type from binary to text, but that did not work. The
current section of code I have is the following:

Public Function ChangeColumnType(ByVal StrgTableName As String, _
strgColumnName As String, StrgNewDataType) As Boolean

On Error GoTo Err_ChangeColumnType

DoCmd.RunSQL "ALTER TABLE [" & StrgTableName & "] ADD COLUMN [" &
strgColumnName & "-NEW] " & StrgNewDataType
DoCmd.RunSQL "UPDATE [" & StrgTableName & "] SET [" &
strgColumnName & "-NEW] = [" & strgColumnName & "]"
DoCmd.RunSQL "ALTER TABLE [" & StrgTableName & "] DROP COLUMN [" &
strgColumnName & "]"
ChangeColumnType = RenameColumn(StrgTableName, strgColumnName &
"-NEW", strgColumnName)

Exit_ChangeColumnType:
Exit Function

Err_ChangeColumnType:
MsgBox "There was an Error while changing the Table Column [" &
strgColumnName & "] to [" & _
StrgNewDataType & "] within the Table named [" & StrgTableName & "]
" _
, vbCritical, "Column Retype Error"
GoTo Exit_ChangeColumnType
End Function
Unfortunately this does not work. For some reason it wont drop the
old attibute and rename the newly created attribute. Instead it
errors out. Anyone have some suggestions? I would appreciate any
and all help.
Thanks,
Erica


As usual I'm going to as "why???". I simply can't see a good reason to
ever dynamically change the database table design like this.
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 29 '05 #2

Er**********@gmail.com wrote:
I have an access program that needs to change the data types
programatically. I have tried to do an alter column to change the
original data type from binary to text, but that did not work.


What version of Access?

This works in 2003.

CurrentProject.AccessConnection.Execute "ALTER TABLE SecondTable ALTER
COLUMN Product1 Text (255)"

Nov 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eternally | last post by:
Hey folks, To me, this sounds like a crazy question, but I'll throw it out there anyway. Is it possible to change a variables data type half way through a running program? If so, how? ...
1
by: iporter | last post by:
Hi - I am changing a field from type nvarchar to type text, given that I need to store strings longer than 255 characters. To do this I change the data type in SQL Server, then I change the...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
13
by: Peter | last post by:
Can anyone tell me how to change the data type of a field in a table created with a make table query? The field is a binary and must be changed to text. alternately does anyone know how to specify...
4
by: Geir Baardsen | last post by:
Hi! I seem to have some very empty spaces in my head. Could you help me fill them? Dim intNumber As Integer 'Get value from field in table that is text intNumber = DMax("",...
2
by: S P Arif Sahari Wibowo | last post by:
Hi! Do you know how to put a form's Access-Visual-Basic-code that will force the form to be inserted, while the user has not type anything in the form, without changing focus, selection, etc.? ...
4
by: andychambers2002 | last post by:
I'm working on a "TempFile" class that stores the data in memory until it gets larger than a specified threshold (as per PEP 42). Whilst trying to implement it, I've come across some strange...
45
by: alertjean | last post by:
Or may be I am stubborn or dumb ... of not putting in a * in the typecast. This is code I am worrying about long long b=1; int *address ; address=(int)&b; printf ("%x %x...
5
by: veer | last post by:
hello expert can any one help me by providing the method how can i change the data type of column in sql server originally my column data type is numeric and i want to change it into integer i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.