五个月前,我在此问题上得到了帮助:
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
我想访问的是:
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按钮配合使用