【问题标题】:Modifying Column Data Format Using Alter Table Add Column使用 Alter Table Add Column 修改列数据格式
【发布时间】:2016-08-19 16:29:32
【问题描述】:

我正在尝试使用 Excel VBA 在 Access 表的新列中修改数据类型的字段大小。我有以下有效的代码:

InsertDataCommand = "ALTER TABLE " & TableName & " ADD COLUMN " & ColumnName & " "
Select Case DataType
    Case Is = "TEXT"
        InsertDataCommand = InsertDataCommand & DataType & "(" & DataLength & ")"
    Case Is = "NUMBER"
        InsertDataCommand = InsertDataCommand & DataType
End Select

AccessObject.CurrentProject.Connection.Execute (InsertDataCommand)

我的问题是我的一些数字需要 Double 格式,有些需要 Long Integer 格式。我找不到任何有关如何指定 TEXT 字段长度的文档。有什么想法吗?

【问题讨论】:

    标签: vba excel ms-access


    【解决方案1】:

    好的,我想通了。非常简单。

    InsertDataCommand = "ALTER TABLE " & TableName & " ADD COLUMN " & ColumnName & " "
    Select Case DataType
        Case Is = "TEXT"
            InsertDataCommand = InsertDataCommand & DataType & "(" & DataLength & ")"
        Case Is = "LONG INTEGER"
            InsertDataCommand = InsertDataCommand & DataType
        Case Is = "DOUBLE"
            InsertDataCommand = InsertDataCommand & DataType
        Case Is = "MEMO"
            InsertDataCommand = InsertDataCommand & DataType
        Case Is = "DATE"
            InsertDataCommand = InsertDataCommand & DataType
    End Select
    
    AccessObject.CurrentProject.Connection.Execute (InsertDataCommand)
    

    我认为 Number 类型必须指定与 Text 类型相同的语句,但可惜它没有。

    【讨论】:

      猜你喜欢
      • 2011-02-06
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2018-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多