在添加数据的时候,我们可能判断需要判断该字段的数据类型
因为数据类型的限制,未必能正常录入。而且不同数据类型,对于获取变量的写法也不一样,详细代码:
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")