office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access获取字段的数据类型

2020-06-21 08:00:00
tmtony8
原创
2882

在添加数据的时候,我们可能判断需要判断该字段的数据类型

因为数据类型的限制,未必能正常录入。而且不同数据类型,对于获取变量的写法也不一样,详细代码:

Function myfun(fld, sqlStr) As String
    
    Dim rs As New ADODB.Recordset
    rs.Open sqlStr, CurrentProject.Connection, adOpenKeyset, adLockPessimistic
   
     Dim typ As Integer
    Dim variant_type As Variant
    typ = rs.Fields("" & fld & "").Type

    Select Case typ
    Case 202, 203
        variant_type = "文本"
    Case 2, 3, 4, 5, 6, 17, 131
        variant_type = "数字"
    Case 7
        variant_type = "日期/时间"
    Case 9
        variant_type = "ole对象"
    Case 11
        variant_type = "布尔"
    Case 0
        variant_type = "empty"
    Case 1
        variant_type = "null"
    Case 10
        variant_type = "error"
    Case Else
        variant_type = "其他的数据类型"
    End Select
    myfun = variant_type
End Function

  

调用函数:myfun("交易类型","yw")


    分享