office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

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

Access穫取字段的數據類型

2020-06-21 08:00:00
tmtony8
原創
2883

在添加數據的時候,我們可能判斷需要判斷該字段的數據類型

因爲數據類型的限製,未必能正常録入。而且不衕數據類型,對於穫取變量的寫法也不一樣,詳細代碼:

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")


    分享