事件代码 [英] Event Code

查看:144
本文介绍了事件代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为EmpRpt的表格。它有三个领域。第一个字段是

" chrUserID,"这是一个包含来自另一个表的行源的组合框。

第二栏是BeginDate。第三个字段是EndDate。


然后我有一个命令按钮。我想点击这个按钮点击

事件。代码应该打开一个名为EmpRpt的报告。


报告将有三个字段,就像表格一样。我希望这三个

字段与用户在表单中输入的数据一起显示。我也会像打印预览一样打开这个报告。


有人可以帮我一个代码吗?谢谢!


-

通过AccessMonster.com发布消息
http://www.accessmonster.com/Uwe/For...ccess/200708/1

I have a form called "EmpRpt". It has three fields. First field is
"chrUserID," this is a combo box with a row source from another table. The
Second Field is "BeginDate." The Third field is "EndDate."

I then have a command button. I want to put a code in this buttons on click
event. The code should open up a report called "EmpRpt."

The report will have the three fields just like the form. I want those three
fields to appear with the data the user entered in the form. I would also
like this report to open in print preview.

Can someone please help me with a code? Thank you!

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200708/1

推荐答案

请参阅:

打印表格中的记录

at:
http://allenbrowne.com/casu-15.html


请注意,您的表必须有一个主键,因此您可以确定

报告具有相同的记录。


-

Allen Browne - 微软MVP。西澳大利亚珀斯

访问用户提示 - http:// allenbrowne .com / tips.html

回复群组,而不是mvps dot org的allenbrowne。


来自AccessMonster.com的瓢虫 < u21071 @ uwewrote in message

news:767016588cee4 @ uwe ...
See:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

Note that your table must have a primary key so you can be certain the
report has the same record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"ladybug via AccessMonster.com" <u21071@uwewrote in message
news:767016588cee4@uwe...

>我有一个名为EmpRpt的表格。它有三个领域。第一个字段是

" chrUserID,"这是一个包含来自另一个表的行源的组合框。



第二个字段是BeginDate。第三个字段是EndDate。


然后我有一个命令按钮。我想在这个按钮上放一个代码

点击

事件。代码应该打开一个名为EmpRpt的报告。


报告将有三个字段,就像表格一样。我希望那些

三个

字段与用户在表单中输入的数据一起显示。我也会像打印预览一样打开这个报告。


有人可以帮我一个代码吗?谢谢!
>I have a form called "EmpRpt". It has three fields. First field is
"chrUserID," this is a combo box with a row source from another table.
The
Second Field is "BeginDate." The Third field is "EndDate."

I then have a command button. I want to put a code in this buttons on
click
event. The code should open up a report called "EmpRpt."

The report will have the three fields just like the form. I want those
three
fields to appear with the data the user entered in the form. I would also
like this report to open in print preview.

Can someone please help me with a code? Thank you!


瓢虫通过AccessMonster.com写道:
ladybug via AccessMonster.com wrote:

我有一个名为EmpRpt的表格;。它有三个领域。第一个字段是

" chrUserID,"这是一个包含来自另一个表的行源的组合框。

第二栏是BeginDate。第三个字段是EndDate。


然后我有一个命令按钮。我想点击这个按钮点击

事件。代码应该打开一个名为EmpRpt的报告。


报告将有三个字段,就像表格一样。我希望这三个

字段与用户在表单中输入的数据一起显示。我也会像打印预览一样打开这个报告。


有人可以帮我一个代码吗?谢谢!
I have a form called "EmpRpt". It has three fields. First field is
"chrUserID," this is a combo box with a row source from another table. The
Second Field is "BeginDate." The Third field is "EndDate."

I then have a command button. I want to put a code in this buttons on click
event. The code should open up a report called "EmpRpt."

The report will have the three fields just like the form. I want those three
fields to appear with the data the user entered in the form. I would also
like this report to open in print preview.

Can someone please help me with a code? Thank you!



你可以创建一个名为EmpRpt的查询。添加2个表(因为

组合已链接)您使用并从2

表中向下拖动您想要的字段。保存查询。


转到报告,单击新建,然后使用报告向导。选择查询

EmpRpt。按照步骤创建报告。将其保存为EmpRpt。


现在在命令按钮中打开属性表到事件选项卡

并选择OnCLick事件。您可以输入

Docmd.OpenReport" EmpRpt",acViewPreview


您也可以过滤它。假设您有一个名为EmpID的字段,

它是数字。你可以输入

Docmd.OpenReport" EmpRpt",acViewPreview ,," EmpID =" &安培; Me.chrUserID

这将显示当前empid的报告。


现在你可以打开一份所有数据的报告没有

被保存了。如果这是一个新记录,报告甚至可能会说没有

数据存在!因此,有时您可能希望在显示报告之前先保存记录

。您的代码可能如下所示

如果Me.Dirty然后Me.Dirty = False

Docmd.OpenReport ...



如果Me.Dirty然后DoCmd.RunCommand acCmdSaveRecord

Docmd.OpenReport ...

You could create a query called EmpRpt. Add the 2 tables (since the
combo is linked) you use and drag down the fields you want from the 2
tables. Save the query.

Go to Reports, click New, and use the ReportWizard. Select the query
EmpRpt. Follow the steps to create the report. Save it as EmpRpt.

Now in your command button you open the property sheet to the event tab
and select the OnCLick event. You could enter
Docmd.OpenReport "EmpRpt",acViewPreview

You can filter it as well. Lets say you have a field called EmpID and
it is numeric. You could enter
Docmd.OpenReport "EmpRpt",acViewPreview,,"EmpID = " & Me.chrUserID
and this will display the report for the current empid.

Now it''s possible you might open a report where all of the data has not
been saved. If this were a new record, the report might even say no
data exists! So sometimes you might want to save the record first
before displaying a report. Your code might look like this
If Me.Dirty then Me.Dirty = False
Docmd.OpenReport...
or
If Me.Dirty then DoCmd.RunCommand acCmdSaveRecord
Docmd.OpenReport...


我做了你给我的我发了一个错误,我输入了一个表达式

,它对该属性脏的引用无效。我拿出那段代码

然后打开报告,但没有捕获数据。这是我的

代码:


Private Sub Command6_Click()

Dim strWhere as String


如果是Me.NewRecord然后''检查是否有要打印的记录

MsgBox"选择要打印的记录

否则

strWhere =" [chrUserId] =" &安培;我。[chrUserID]

DoCmd.OpenReport" EmpRpt",acViewPreview ,, strWhere

结束如果

End Sub

Allen Browne写道:
I did what you gave me and I rcvd an error that I have entered an expression
that has an invalid reference to the property dirty. I took out that section
of the code and it opens the report, but no data is captured. Here is the
code I have:

Private Sub Command6_Click()
Dim strWhere As String

If Me.NewRecord Then ''Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[chrUserId] = " & Me.[chrUserID]
DoCmd.OpenReport "EmpRpt", acViewPreview, , strWhere
End If
End Sub
Allen Browne wrote:

>参见:


格式打印记录: http://allenbrowne.com/casu-15.html

请注意,您的表必须有一个主键,因此您可以确定
报告具有相同的记录。
>See:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

Note that your table must have a primary key so you can be certain the
report has the same record.

>> ;我有一个名为EmpRpt的表格。它有三个领域。第一个字段是chrUserID,这是一个包含来自另一个表的行源的组合框。
>>I have a form called "EmpRpt". It has three fields. First field is
"chrUserID," this is a combo box with a row source from another table.


[引用文字剪辑 - 11行]

[quoted text clipped - 11 lines]


>>
有人可以帮助我一个代码?谢谢!
>>
Can someone please help me with a code? Thank you!



-

通过AccessMonster.com发布消息
http://www.accessmonster.com/Uwe/For...ccess/ 200708/1

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200708/1


这篇关于事件代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆