怎么读取一个Access表中某一列的字段的数据类型
1个回答
展开全部
Function GetFieldType(ByVal TabelName As String, ByVal FieldName As String) As String
On Error GoTo ErrHand
Dim T As TableDef
Dim Ts As TableDefs
Dim F As Field
Set Ts = CurrentDb.TableDefs
Set T = Ts(TabelName)
For Each F In T.Fields
If F.Name = FieldName Then
Select Case F.Type
Case dbBigInt: GetFieldType = "大整数"
Case dbBinary: GetFieldType = "二进制"
Case dbBoolean: GetFieldType = "布尔型"
Case dbByte: GetFieldType = "字节"
Case dbChar: GetFieldType = "字符"
Case dbCurrency: GetFieldType = "货币"
Case dbDate: GetFieldType = "日期/时间"
Case dbDecimal: GetFieldType = "小数"
Case dbDouble: GetFieldType = "双精度型"
Case dbFloat: GetFieldType = "浮点型"
Case dbGUID: GetFieldType = "GUID"
Case dbInteger: GetFieldType = "整型"
Case dbLong: GetFieldType = "长整型"
Case dbLongBinary: GetFieldType = "长二进制(OLE 对象)"
Case dbMemo: GetFieldType = "备注"
Case dbNumeric: GetFieldType = "数字"
Case dbSingle: GetFieldType = "单精度型"
Case dbText: GetFieldType = "文本"
Case dbTime: GetFieldType = "时间"
Case dbTimeStamp: GetFieldType = "时间戳"
Case dbVarBinary: GetFieldType = "VarBinary"
End Select
End If
Next
ExitFunc:
Set T = Nothing
Set F = Nothing
set ts=nothing
Exit Function
ErrHand:
If Err.Number = 3265 Then
MsgBox "当前数据库没有找到指定表名[" & TabelName & "]"
Else
MsgBox Err.Number & Err.Description
End If
GoTo ExitFunc
End Function
把上面的代码复制到一个标准模块中
使用方式 在任何地方用
GetFieldType( "表名","字段名")
就可以返回字段类型
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询