fggg dfg sdfsdf dfgfg sddsf
Rename Field Name for a tableSub Rename_Field_Names() ' The purpose of this macro is to rename the field name since ' DoCmd.Rename newTableName(i), acTable, oldTableName(i) ' did not work for the field object ' Table and Field names don't name like "A person" or "a Thing" or "ID#" ' This is because SQL did not like space between words in the table and field names Const dimMax = 50 Dim oldFieldName(dimMax), newFieldName(dimMax), newFieldType(dimMax) As String Dim tempTableName As String Dim mySQL, mySQL_Add, mySQL_Update, mySQL_Drop As String Dim fieldCount As Integer newFieldName(1) = "A" newFieldName(2) = "B" newFieldName(3) = "C" oldFieldName(1) = "Apple" oldFieldName(2) = "Banana" oldFieldName(3) = "Cherry" newFieldType(1) = "text" newFieldType(2) = "text" newFieldType(3) = "text" tempTableName = "Table1" fieldCount = 0 For i = 1 To dimMax If oldFieldName(i) <> "" Then fieldCount = fieldCount + 1 End If Next i For i = 1 To fieldCount 'Create a new column field mySQL_Add = "ALTER" mySQL_Add = mySQL_Add + " TABLE " & tempTableName mySQL_Add = mySQL_Add + " ADD" mySQL_Add = mySQL_Add + " COLUMN " & newFieldName(i) & " " & newFieldType(i) DoCmd.SetWarnings False DoCmd.RunSQL mySQL_Add & ";" DoCmd.SetWarnings True 'Copy the data from the old column to the new column mySQL_Update = "UPDATE" mySQL_Update = mySQL_Update + " " & tempTableName mySQL_Update = mySQL_Update + " SET " & newFieldName(i) & " = " & oldFieldName(i) DoCmd.SetWarnings False DoCmd.RunSQL mySQL_Update & ";" DoCmd.SetWarnings True 'Drop the old column mySQL_Drop = "ALTER" mySQL_Drop = mySQL_Drop + " TABLE " & tempTableName mySQL_Drop = mySQL_Drop + " DROP COLUMN " & oldFieldName(i) DoCmd.SetWarnings False DoCmd.RunSQL mySQL_Drop & ";" DoCmd.SetWarnings True Next iEnd Sub .msgcontent .wsharing ul li { text-indent: 0; } 分享 Facebook Plurk YAHOO!
好站連結:http://tw.myblog.yahoo.com/scott435936176