Office中国论坛/Access中国论坛

标题: How to Fill a List Box with a List of Reports [打印本页]

作者: tmtony    时间: 2005-8-16 21:01
标题: How to Fill a List Box with a List of Reports
标题: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.
作者: chajiangliang    时间: 2005-8-17 06:09


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

原作者: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"數據庫里面是如何進一步擴充此主題, 將一組文件名放入到命令組合框中﹐并在選中組合框中的報表后預覽此報表.

-------以上翻譯朮語部分可能不夠准確﹐請多多指教
作者: 爱情插班生    时间: 2005-8-17 16:14
标题:如何在一列表框中列出所需要的报表名清单.

原作者: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

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

[attach]12495[/attach]

[em01][em01][em01]

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


作者: qlm    时间: 2006-4-21 06:34
有意思!
作者: 阿智    时间: 2007-4-15 18:20
有的学习




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3