设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

Print the record in the form

[复制链接]
跳转到指定楼层
1#
发表于 2005-9-28 22:59:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
文章标题:Print the record in the form

文章来源:http://allenbrowne.com/casu-15.html

原文:

How do you print just the one record you are viewing in the form?

Create a report, to get the layout right for printing. Use the primary key value that uniquely identifies the record in the form, and open the report with just that one record.

The stepsOpen your form in design view.

If you do not see the toolbox, open it from the View menu.

Click the command button in the toolbox, and click on your form.

If the wizard starts, cancel it. It will not give you the flexibility you need.

Right-click the new command button, and choose Properties. Access opens the Properties box.

On the Other tab, set the Name to something like: cmdPrint

On the Format tab, set the Caption to the text you wish to see on the button, or the Picture if you would prefer a printer or preview icon.

On the Event tab, set the On Click property t [Event Procedure]

Click the Build button (...) beside this. Access opens the code window.

Paste the code below into the procedure. Replace ID with the name of your primary key field, and MyReport with the name of your report. The codePrivate Sub cmdPrint_Click()

    Dim strWhere As String



    If Me.Dirty Then    'Save any edits.

        Me.Dirty = False

    End If



    If Me.NewRecord Then 'Check there is a record to print

        MsgBox "Select a record to print"

    Else

        strWhere = "[ID] = " & Me.[ID]

        DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

    End If

End SubNotesIf your primary key is a Text type field (not a Number type field), you need extra quotes:

   strWhere = "[ID] = """ & Me.[ID] & """"

The report will not filter correctly if it is already open.

If you want the report to print without preview, replace acViewPreview with acViewNormal.



译文:

在窗体中打印记录

怎样打印窗体中的一条记录?

建立一个报表,为打印调好正确的格式,使用主键值:就是在窗体中能够唯一识别的字段。像刚才那样打开那条记录。

步骤:

1.       打开窗体的设计模式。

2.       如果你看不到工具箱,你可以在视图菜单里调出工具栏。

3.       在工具箱里点击命令按钮,然后在你的窗体中点击。

4.       如果向导开始,取消它。它不能够给你适合的需要。

5.       正确的点击新建命令按钮,然后选择道具,ACCESS就会打开道具箱。

6.       在另一个标号,设置一些像cmdPrint的名字。

7.       在格式框里,设置文本属性你想要知道的按钮。或者图片你要适合打印预览。

8.       在事件里,设置点击到:[Event Procedure]

9.       点击造型按钮,ACCESS会打开到代码。

10.   粘贴里面程序的代码,替换ID用名字领域的主键。然后命名报表名字为“我的报表”。

代码:Private Sub cmdPrint_Click()    Dim strWhere As String     If Me.Dirty Then    'Save any edits.        Me.Dirty = False    End If     If Me.NewRecord Then 'Check there is a record to print        MsgBox "Select a record to print"    Else        strWhere = "[ID] = " & Me.[ID]        DoCmd.OpenReport "MyReport", acViewPreview, , strWhere    End IfEnd Sub注意:

1.       如果你的猪键是文本类型(不是数字类型),你需要特别的引用:

         strWhere = "[ID] = """ & Me.[ID] & """"

2.    报表打开后不适合已经打开的。

3.       如果你需要打印没打印预览,替换acViewPreview with acViewNormal.





翻译:飞天业
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-3 09:50 , Processed in 0.301623 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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