您现在的位置: 中国男护士网 >> 考试频道 >> 计算机等级 >> 二级辅导 >> ACCESS >> 辅导 >> 正文    
  如何设置组合框或列表框的行来源为函数 【注册男护士专用博客】          

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

www.nanhushi.com     佚名   不详 

  下列代码是一个例程,将行来源设置为这个函数:

  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

  相关链接:

  2008年下半年全国计算机等级考试报名信息汇总

  更多信息请访问:计算机等级考试站 计算机等级考试在线题库 计算机等级考试论坛

 

文章录入:杜斌    责任编辑:杜斌 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     

    联 系 信 息
    QQ:88236621
    电话:15853773350
    E-Mail:malenurse@163.com
    免费发布招聘信息
    做中国最专业男护士门户网站
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关文章
    专 题 栏 目

      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)                            【进男护士社区逛逛】
    姓 名:
    * 游客填写  ·注册用户 ·忘记密码
    主 页:

    评 分:
    1分 2分 3分 4分 5分
    评论内容:
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。