如何设置组合框或列表框的行来源为函数
如何设置组合框或列表框的行来源为函数
下列代码是一个例程,将行来源设置为这个函数:
Public Function valueList(ctl As Control, _
varID As Variant, _
lngRow As Long, _
lngCol As Long, _
intCode As Integer) As Variant
Dim varRetVal As Variant
Dim strField As String
Dim strField As String
Dim strSQL As String
Dim strList As String
Dim intLoopRow As Integer
Dim intLoopCol As Integer
Dim cnn As ADODB.Connection
Dim RST As ADODB.Recordset
Static svarArray() As Variant
Static sintRows As Integer
Static sintCols As Integer
On Error GoTo Proc_err
Select Case intCode
Case acLBInitialize
On Error Resume Next
intLoopRow = Ubound(svarArray)
If Err <> 0 Then
On Error GoTo Proc_err
'populate the customer recordset
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Properties("Data Source") = CurrentProject.Path & "\data share\data.dat"
cnn.Properties("Jet OLEDB:Database Password") = "123456789222"
cnn.Open
' With cnn
'.Provider = "Microsoft.Jet.OLEDB.4.0"
'this gets stored values from the only
'local table to allow flexibility
'.ConnectionString = CurrentProject.Path & "\data.dat" 'should be changed
'.Properties("Jet OLEDB:Database Password") = "123456789222"
'.Open
'End With
Set RST = New ADODB.Recordset
With RST
.ActiveConnection = cnn
.Source = "select usysuser.userid,usysuser.username from usysuser" 'should be changed
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockReadOnly
.Open , , , , adCmdText
.MoveLast
sintRows = .RecordCount
.MoveFirst
sintCols = .Fields.Count
End With 'rst
Set cnn = Nothing
ReDim svarArray(sintRows, sintCols)
For intLoopRow = 0 To sintRows - 1
svarArray(intLoopRow, 0) = RST(0)
svarArray(intLoopRow, 1) = RST(1)
' MsgBox rst(0) & rst(1)
RST.MoveNext
Next
RST.Close
End If
varRetVal = True
Case acLBOpen '1
'return a unique ID code
varRetVal = Timer
Case acLBGetRowCount '3
' Return number of rows
varRetVal = sintRows
Case acLBGetColumnCount '4
' Return number of fields (columns)
varRetVal = sintCols
Case acLBGetColumnWidth '5
'return the column widths or
'-1 for the default width for the column
' varRetVal = -1 'default width
Select Case lngCol
Case 0
'hide the first column
varRetVal = 0
Case 1
'return the default width for column 2
varRetVal = -1
End Select
Case acLBGetValue '6
'Return actual data
varRetVal = svarArray(lngRow, lngCol)
'If lngRow = 0 Then
'varRetVal = Null
' End If
Case acLBGetFormat '7
'return the formatting info for the row/column
Select Case lngCol
Case 0
Case 1
End Select
Case acLBEnd '9
'clean up
On Error Resume Next
Erase svarArray
Set RST = Nothing
Set cnn = Nothing
End Select
Proc_exit:
On Error Resume Next
valueList = varRetVal
Exit Function
Proc_err:
'MsgBox Err.Number & "--" & Err.Description & vbCrLf & "CustomerList"
varRetVal = False
Resume Proc_exit
End Function
(责任编辑:admin)
- ·Access窗体居中显示技巧
- ·Access中Tab键的使用说明【技巧】
- ·Access粘贴对象到Tab选卡上的技巧
- ·Access在窗体上显示当前记录和总记录数
- ·Access隐藏组合框的小箭头
- ·Access窗体属性表
- ·【技巧】Access选项组边框变为圆角边框
- ·Access函数me.sfmsub.form 提示子窗体
- ·Access中使用缩放对话框显示文本框文字
- ·access技巧-中文显示星期几的简单方法
- ·Access控件是否可见,可编辑,锁定的技巧
- ·根据查找窗体设定的条件筛选主窗体的数
- ·父子窗体的语法介绍
- ·access实现组合框联动详细教程
- ·Web Service在Access中的应用技巧
- ·Access窗体最大化,最小化等操作