首页 > 解决方案 > 仅新记录,当子表单有记录时

问题描述

五个月前,我得到了解决这个问题的帮助:
Auto next number count to specific selection

我需要在建筑工地进行每日报告的自动计数。现在我的问题是,代码

Dim NextNumber As Long
NextNumber = Nz(DMax("[raumBTBNR]", "[tbl_RaeumstellenErfassung]", "[raeumKostenstelleIDRef] = " & Me!KostenstelleAuswahl.Value & ""), 0) + 1
Me!Nummer = NextNumber

放置在SelectingCostCentre_AfterUpdate (其工作正常)

结果:
如果一个员工要写日报:
他打开程序,选择他所在的匹配的工地,日报数计数+1。到目前为止一切顺利...如果他现在要离开程序,或者在未在活动表单中添加员工的情况下单击另一个表单 尽管如此,Access 还是保存了记录。
当他现在想再次输入记录时,他必须再次输入他的建筑工地,但自动报告​​编号不再正确,因为他再次计数+1。这与 Form_Open 的DoCmd.GoToRecord , , acNewRec有关

表格看起来像这样

我想要访问的是:

When opening the form, check if the last record (of the specific constr. site) at table 
"Constructionsite entry" has entries at the table "activity log"
If True 
    DoCmd.GoToRecord , , acNewRec
Else 
    Open Last Record of the matching constuction site

编辑: 或类似的东西:

If no data entries at table "activity log" available
Recordset current delete

显然,我的 VBA 技能非常基础......如果有的话。我查看了函数 DLookup,但不知道如何处理此类问题的语法。

EDIT2 获得了解决方案的第一步:

If DCount("*", "tbl_RaeumstellEnerfassung", _
          "RaeumKostenstelleIDRef=" & Me!KostenstelleAuswahl & " " & _
               "AND raeumDatum =" & Format(Me!raeumDatum, _
                                       "\#yyyy-mm-dd\#")) > 1 Then
                If MsgBox("Die Räumstelle " & Me![KostenstelleAuswahl].Column(1) & " ist am  " & Me![raeumDatum] & " schon eingetragen worden!" & vbCrLf & "Trotzdem fortfahren?", vbQuestion + vbYesNo) = vbNo Then
         DoCmd.GoToRecord , , acLast
         DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
      Else
         Cancel = False
    End If
    End If

他检查是否已经输入了建筑工地编号和日期。我想做的是有第三个 MsgBox 按钮作为 Dlookup 或 DLast,它向我显示与该建筑工地相关的最后数据。

DLookup("[raeumID]", "tbl_RaeumstellenErfassung", "[KostenstellenIDRef] ="Forms![frm_RaeumstellenErfassung]![KostenstellenAuswahl]")

显然这不起作用..更准确地说,我不能让它与 3d 按钮一起使用

标签: ms-accessvba

解决方案


推荐阅读