|
也可以用这个函数(我一直用的,相对要麻烦一点)
Function ColType(ByVal TabelName As String, ByVal ColName As String)
'TabelName---表名称
'ColName---字段名称
'由于动态查询、筛选需要过滤某些内容,但是不知道某字段是文本、日期、数字类型,会导致代码错误,本函数返回某表某字段的数据类型的那个符号(对应"'"、"#"、"")
'
Dim str
Dim B
Dim A
Dim C
Dim st
Dim Conn As ADODB.Connection
Set Conn = CurrentProject.Connection
Dim rc As ADODB.Recordset
Set rc = New ADODB.Recordset
rc.Open "select top 1 * from " & TabelName, Conn, adOpenStatic, adLockReadOnly
For i = 0 To rc.Fields.Count - 1
B = rc.Fields(i).Type
A = rc.Fields(i).Name
If A = ColName Then
C = B
Exit For
End If
Next i
Select Case C
Case 3, 131, 6
st = ""
Case 7
st = "#"
Case Else
st = "'"
End Select
Debug.Print st
ColType = st
End Function
|
|