ms-access - 仅新记录,当子表单有记录时
问题描述
五个月前,我得到了解决这个问题的帮助:
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 按钮一起使用
解决方案
推荐阅读
- angular - Angular:从路由更改父组件的字段
- css - 使用 VUE CLI 3 配置 SASS 加载器(替换 Koala-app)
- java - 数组的索引超出范围(java)
- html - 如何解决没有在 Django 模板上加载的 CSS 背景图像
- android - Flutter:ListView 里面的 ListView.builder
- autodesk-forge - Forge Viewer:搜索或模型浏览器
- reactjs - 如何在反应中向 Firebase REST API 发送 POST 请求
- python - Python & Google Sheets - 在第 5 行和第 3 列中查找元素
- c - 将 c 程序中的内存与 AVX 的外部程序集对齐
- python - 当我从文件中提取数据时尝试在 python 脚本中使用 read(\n) 时出现 TypeError