vba - Different AutoNumbers to specific selection
问题描述
I need some vba help at my Access project.
In our company we got different construction sites. Each construction site have their own cost centre. We have to make reports to each construction sites related to the cost centre. These reports have their own continious number(related to the cost centres)
I got a formular, where I can choose the cost centre and want to be shown the latest report number +1, when making a new input, so no mistakes can happen for users.
Nr. is related to the textfield Nummer with the content raumBTBNR for the increasing Report numbers. Kostenstelle got the combo box called KostenstelleAuswahl with the content raeumKostenstelleIDRef for the cost centres.
Code so far: (credits by Gustav)
Private Sub Nummer_GotFocus()
Dim NextNumber As Long
highest Rep.Nr. related table Content of KostenstelleAuswahl
NextNumber = DMax("[raumBTBNR]", "[tbl_Raeumstellen]", "[KostenstellenIDRef] = " & Me!KostenstelleAuswahl.Value & "") + 1
Me!Nummer = NextNumber
End Sub
My solution right now is a query, where i count the number of the reports, related to the cost centres. But it does not fill automatically and is more worse than nice. Which is saved at MaxNr Example in my form
I would appreciate some help!:)
解决方案
OK, then this should work - when selecting Kostenstelle:
Private Sub KostenstelleAuswahl_AfterUpdate()
Dim NextNumber As Long
NextNumber = DMax("[raumBTBNR]", "[tbl_Raeumstellen]", "[raeumKostenstelleIDRef] = " & Me!KostenstelleAuswahl.Value & "") + 1
Me!Nr.Value = NextNumber
End Sub
推荐阅读
- ios - iOS 测试应用程序 HelloWorld - 此时无法下载应用程序
- bash - 使用 GNU find 递归创建具有随机内容的文件
- java - java.lang.NullPointerException:尝试调用虚拟方法 + Firebase
- html - 如何使用数据库查询的输入在电子邮件中创建 HTML 表
- node.js - 部署到 Heroku 错误:找不到模块“/app/server.js”
- lua - lua tonumber 奇怪的行为
- javascript - Vue.js 中的动态样式
- c# - 尝试将字节数组转换为图像时参数无效
- python - 为什么我不能通过pycharm安装PyQt4?
- javascript - 使用jquery从数组中获取唯一数据