设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 6036|回复: 9
打印 上一主题 下一主题

How to Fill a List Box with a List of Reports

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2005-8-16 21:01:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
标题:How to Fill a List Box with a List of Reports  .

原作者:ATTAC Consulting Group

原文网址:http://ourworld.compuserve.com/homepages/attac-cg/AFormTip.htm#KEY

摘抄人:tmtony

翻译人:

It may be useful to present a user with a list of reports available to print from a specific form in a list box on that form. Here's a method and code that illustrates how to limit a list of reports presented on a form to a specific sub set of reports in your database:

1. Select a prefix to add to the name of the reports you want to display in on the specific form in the List Box. (In the example below, "cmgt_ " is the prefix used.)

2. Set the target list box to use a value list as its Row Source Type

3. Place code like the following to the "On Open" event of the form you are using; note that the code is version independent and will work in Access 97 and above: Sub Form_Open (Cancel As Integer)

On Error GoTo ErrHandler

Dim App As Object

Dim CurProject As Object

Dim CollReports As Object

Dim objRpt As Object

Dim strRptName As String, strReportList as String, i As Integer



If SysCmd(acSysCmdAccessVer) < 9 Then

    i = 0

    Set CurProject = CurrentDb

    Set CollReports = CurProject.Containers("Reports")

    For i = 0 To CollReports.Documents.Count - 1

        strRptName = CollReports.Documents(i).Name

        If instr(strRptName, "_cmgt")>0 Then

            strReportList = strReportList & strRptName & ";"

        End If

    Next i

Else

    Set App = Application

    Set CurProject = App.CurrentProject

    Set CollReports = CurProject.AllReports

    For Each objRpt In CollReports

        strRptName = objRpt.Name

        If instr(strRptName, "_cmgt")>0 Then

            strReportList = strReportList & strRptName & ";"

        End If

    Next

End If

  'knock of the last ";"

  strReportList = Left(strReportList, Len(strReportList)-1)  

   

  Me!RptLstBox.RowSource = strReportList



ExitProc:

     Exit Sub

ErrHandler:

    MsgBox Err & " " & Error, , "Form Open"

    Resume ExitProc

End Sub

Check out the "Other Reports" database in our free files area to see how extend this concept to load a list of reports into a command bar combo box and preview that report when the command bar combo is selected.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2005-8-17 06:09:00 | 只看该作者


如何在列表框中列舉一組報表

原作者:ATTAC 咨詢 集團

原文网址:http://ourworld.compuserve.com/homepages/attac-cg/AFormTip.htm#KEY

摘抄人:tmtony

翻译人: chajiangliang

在一個特定的窗體上給用戶提供一組可供打印的報表的列表框可能是有用的。在此有個方法及相應原碼可以演示如何在窗體上制作一個列表框﹐并限定其資料來源為你的數據庫中的某些報表.

1. 給你想要在特定窗體上顯示的報表的名字加一個前綴(在以下的例子中﹐將使用"cmgt_ "做前綴)2. 設定目標列表框的資料來源類型為值清單.3. 將以下代碼復制到你使用的窗體的"On Open"事件下﹔注意著段代碼是可運行在Access97及以上版本中: Sub Form_Open (Cancel As Integer)

On Error GoTo ErrHandler

Dim App As Object

Dim CurProject As Object

Dim CollReports As Object

Dim objRpt As Object

Dim strRptName As String, strReportList as String, i As IntegerIf SysCmd(acSysCmdAccessVer) < 9 Then

    i = 0

    Set CurProject = CurrentDb

    Set CollReports = CurProject.Containers("Reports")

    For i = 0 To CollReports.Documents.Count - 1

        strRptName = CollReports.Documents(i).Name

        If instr(strRptName, "_cmgt")>0 Then

            strReportList = strReportList & strRptName & ";"

        End If

    Next i

Else

    Set App = Application

    Set CurProject = App.CurrentProject

    Set CollReports = CurProject.AllReports

    For Each objRpt In CollReports

        strRptName = objRpt.Name

        If instr(strRptName, "_cmgt")>0 Then

            strReportList = strReportList & strRptName & ";"

        End If

    Next

End If

  'knock of the last ";"  

  strReportList = Left(strReportList, Len(strReportList)-1)  

   

  Me!RptLstBox.RowSource = strReportListExitProc:

     Exit Sub

ErrHandler:

    MsgBox Err & " " & Error, , "Form Open"

    Resume ExitProc

End Sub你還可以在我們的免費檔案版塊中查看"Other Reports"數據庫里面是如何進一步擴充此主題, 將一組文件名放入到命令組合框中﹐并在選中組合框中的報表后預覽此報表.

-------以上翻譯朮語部分可能不夠准確﹐請多多指教
3#
发表于 2005-8-17 16:14:00 | 只看该作者
标题:如何在一列表框中列出所需要的报表名清单.

原作者:ATTAC Consulting Group

原文网址:http://ourworld.compuserve.com/homepages/attac-cg/AFormTip.htm#KEY

摘抄人:tmtony

翻译人:爱情(意译)

有时候在你操作的窗体中的一个列表框里列出你所以需要打印报表名,(双击可以打开预览或打印。)这让会用户操作起来比较爽。 下面就来介绍如何将所需要用到的报表名加入到这个列表框中。

1. 给报表名加前缀(如:my_报表名),表示有这个前缀的报表名,即是我们将用到的,显示在列表框中。

2. 在这个列表框的属性中的“行来源类型”设为:值列表。

3. 将下面代码放在您操作窗体的“open”事件里。(注:下面的代码在access 97以上通用。)

Sub Form_Open (Cancel As Integer)

On Error GoTo ErrHandler

Dim App As Object

Dim CurProject As Object

Dim CollReports As Object

Dim objRpt As Object

Dim strRptName As String, strReportList as String, i As Integer

If SysCmd(acSysCmdAccessVer) < 9 Then          '判断access版本,不版本将用不同的代码

    i = 0

    Set CurProject = CurrentDb

    Set CollReports = CurProject.Containers("Reports")

    For i = 0 To CollReports.Documents.Count - 1

        strRptName = CollReports.Documents(i).Name

        If instr(strRptName, "my_")>0 Then

            strReportList = strReportList & strRptName & ";"

        End If

    Next i

Else

    Set App = Application

    Set CurProject = App.CurrentProject

    Set CollReports = CurProject.AllReports

    For Each objRpt In CollReports

        strRptName = objRpt.Name

        If instr(strRptName, "my_")>0 Then

            strReportList = strReportList & strRptName & ";"

        End If

    Next

End If

  '去掉后面 ";" 字符

  strReportList = Left(strReportList, Len(strReportList)-1)      

  Me!RptLstBox.RowSource = strReportList

ExitProc:

     Exit Sub

ErrHandler:

    MsgBox Err & " " & Error, , "Form Open"

    Resume ExitProc

End Sub

思维扩展:如何用一个组合框将代替以上功能,当选中下拉菜单某项报表名时,将打开这个报表的预览。(并附上我做的例子)



[em01][em01][em01]

[此贴子已经被作者于2005-8-17 9:17:09编辑过]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
4#
发表于 2006-4-21 06:34:00 | 只看该作者
有意思!
5#
发表于 2007-4-15 18:20:00 | 只看该作者
有的学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-15 12:55 , Processed in 0.093908 second(s), 30 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表