会计考友 发表于 2012-7-31 22:26:35

如何设置组合框或列表框的行来源为函数

如何设置组合框或列表框的行来源为函数
 下列代码是一个例程,将行来源设置为这个函数:
  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 Err0 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
页: [1]
查看完整版本: 如何设置组合框或列表框的行来源为函数