Alex said:
Hi, I have a bunch of fields that are set as text (Access default)
and I'd like to write a macro (or anything that'd work!) to change
most of them to 'Number', 'double precision'. Is that feasible or do
I have to change them by hand??
Thanks
Alex
I think I'd try to find methods of creating tables which involved
setting datatypes too, so I'll assume this is a one time operation.
Here's a very short thingie without any errortesting or anything, which
should give you the possibility of altering those you want. I'll use
ADO and DDL, though it surely possible through other methods that'll
work too.
If using DDL is OK, though it seem to be a bit frowned upon in these
NGs, here's an article (with links to more) - watch for linebreaks
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acintsql.asp
Sub AlterFieldsToDouble(v_strTable As String)
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = CurrentProject.Connection
Set rs = cn.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, v_strTable, Empty))
Do While Not rs.EOF
If rs.Fields("DATA_TYPE") = adWChar Then
If (MsgBox("Change '" & _
rs.Fields("COLUMN_NAME").Value & "'?", _
vbOKCancel) = vbOK) Then
cn.Execute _
"ALTER TABLE [" & v_strTable & " ] " & _
"ALTER COLUMN [" & _
rs.Fields("COLUMN_NAME").Value & "] DOUBLE"
rs.MoveNext
End If
End If
Loop
End Sub