首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用DoCmd.OpenForm打开表单

使用DoCmd.OpenForm打开表单
EN

Stack Overflow用户
提问于 2020-12-05 03:26:10
回答 1查看 68关注 0票数 0

我正在排除故障,发现一个按钮

似乎不起作用。

我想让按钮打印一个报告(从rptHerstelfiche),其中"IDDefect“为"Volgnr”(在rptHerstelfiche中)。

链接到该按钮的代码。

代码语言:javascript
复制
Option Compare Database
Option Explicit

Private Sub Knop164_Click()
On Error GoTo Err_Afdrukken_technische_gegevens_Click

    Dim stDocName As String
    
    DoCmd.RunCommand acCmdSelectRecord
    stDocName = "rptHerstelfiche"
    'DoCmd.OpenReport "report name", acViewPreview,
    DoCmd.OpenReport stDocName, acPreview, , "Volgnr=" & Me.IDDefect

Exit_Afdrukken_technische_gegevens_Click:
    Exit Sub

Err_Afdrukken_technische_gegevens_Click:
    MsgBox Err.Description
    Resume Exit_Afdrukken_technische_gegevens_Click

End Sub
EN

回答 1

Stack Overflow用户

发布于 2020-12-05 08:25:52

你所拥有的看起来不错,但有几件事:

我建议使用以下代码。并且"select“记录不是必需的。

代码语言:javascript
复制
Dim stDocName As String

if me.Dirty = True then me.Dirty = False  ' force data save
stDocName = "rptHerstelfiche"
DoCmd.OpenReport stDocName, acPreview, , "Volgnr=" & Me.IDDefect

代码语言:javascript
复制
DoCmd.OpenReport stDocName, acViewPreview, , "Volgnr=" & Me.IDDefect

注意acViewPreview的用法。编辑应该建议这个常量。

如果Volgnr是text数据类型,那么该行代码必须变成这样:

代码语言:javascript
复制
DoCmd.OpenReport stDocName, acViewPreview, , "Volgnr = '" & Me.IDDefect & "'"

请注意使用引号将值括起来的要求。

因此,总结一下:

代码语言:javascript
复制
check and use acViewPreview
force the record to be written to the table before you launch report
if you don't' write the record, then the report will show values not yet updated
check if the data type is a number/long/integer type or a text column
if a text column, then surround the value with quotes.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65149565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档