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

似乎不起作用。
我想让按钮打印一个报告(从rptHerstelfiche),其中"IDDefect“为"Volgnr”(在rptHerstelfiche中)。
链接到该按钮的代码。
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发布于 2020-12-05 08:25:52
你所拥有的看起来不错,但有几件事:
我建议使用以下代码。并且"select“记录不是必需的。
Dim stDocName As String
if me.Dirty = True then me.Dirty = False ' force data save
stDocName = "rptHerstelfiche"
DoCmd.OpenReport stDocName, acPreview, , "Volgnr=" & Me.IDDefectDoCmd.OpenReport stDocName, acViewPreview, , "Volgnr=" & Me.IDDefect注意acViewPreview的用法。编辑应该建议这个常量。
如果Volgnr是text数据类型,那么该行代码必须变成这样:
DoCmd.OpenReport stDocName, acViewPreview, , "Volgnr = '" & Me.IDDefect & "'"请注意使用引号将值括起来的要求。
因此,总结一下:
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.https://stackoverflow.com/questions/65149565
复制相似问题