一、Public Function getClassSN() As Boolean
'提前将列表框的记录源排序
Dim SelectedCount As Integer
Dim iCount As Integer
Dim dicID As New Dictionary
For iCount = 0 To Me!班级ID.ListCount - 1
If Me!班级ID.Selected(iCount) = True Then
SelectedCount = SelectedCount + 1
dicID(iCount) = Me!班级ID.Column(1, iCount)
End If
Next iCount
If Me!班级ID.ListCount > 0 And SelectedCount > 1 Then
classMaxSN = (dicID.Item(dicID.Keys(0)))
classMinSN = (dicID.Item(dicID.Keys(UBound(dicID.Keys))))
Else
Exit Function
getClassSN = False
End If
getClassSN = True
Set dicID = Nothing
End Function
二、删除数据库表
用途:删除数据库中的表,可以采用通配符形式如:"A*",可以删除名字首字母为A的表,表不存在不会出现错误信息!
Public Function delTbl(TblName As String)
Dim tbl
For Each tbl In CurrentDb.TableDefs
If tbl.Name Like TblName Then
DoCmd.DeleteObject acTable, tbl.Name
else
Exit Function
End If
Next
Application.RefreshDatabaseWindow
End Function
三
'利用字典存储最大值最小值及其对应ID号,或者第二、第三....最大值,或者第二、第三....最小值,即使最大值、最小值有重复也可以
用法:sql语句要加上排序
Public Function getMinMaxFld(sql As String, tt As Dictionary)
'sql="........ order by 取值字段 desc"
Dim rst As New ADODB.Recordset
rst.Open "select * from XXXX order by YYYY desc", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If rst.RecordCount > 0 Then
rst.MoveFirst
tt.Add rst(0).value, rst(1).value
rst.MoveLast
tt.Add rst(0).value, rst(1).value
End If
rst.Close
Set rst = Nothing
End Function
C:\Users\wzl8007\Desktop\tupian.PNG 作者: pyh512 时间: 2016-8-7 10:33
能不能上传示例容易理解一些作者: 风中漫步 时间: 2016-8-7 12:04
谢谢分享