Access 2013 - 没有自动编号的顺序编号(Access 2013 - sequential numbering without autonumber)
此网站的新功能和访问权限。 我正在尝试创建一个数据库来跟踪主日志。 需要顺序编号方面的帮助。 我目前有以下表格。
PO表 POID - 自动编号(PK)
PODate - 日期/时间
供应商 - 字符串项目表 ItemID - 自动编号(PK)
POID - Ingeter(FK)
ItemDescription - 字符串
数量 - 整数MasterLog表 MasterLogID - 自动编号(PK)
ItemID - 整数(FK)
PieceNumber - 整数(1,2,3 ......等)
MFG - 字符串
进程 - 字符串
长度 - 整数
MfgIDNum - String(ABD123XTY-1234)我正在尝试自动化PieceNumber字段的数据输入。 因此,当您输入新的采购订单并向其添加项目时,一旦收到。 它会在masterlog表中添加一行,从1号开始到我们有多少件。 我们根据我们购买的商品对件进行编号。(对于第1项,我们购买了100件。所以我将第1件1到100件。)然后我们可以将其他数据添加到表中。 只是试图减少一些数据输入时间,并避免在该字段的编号中出现一些错误。
有任何想法吗?
New to this site and access. I am trying to create a database to keep track of a master log. Need help with sequential numbering. I currently have the following tables.
PO Table POID - Autonumber(PK)
PODate - Date/Time
Supplier - StringItem Table ItemID - Autonumber(PK)
POID - Ingeter(FK)
ItemDescription - String
Quantity - IntegerMasterLog Table MasterLogID - Autonumber(PK)
ItemID - Integer(FK)
PieceNumber - Integer ( 1,2,3 ... etc)
MFG - String
Process - String
Length - Integer
MfgIDNum - String (ABD123XTY-1234)I am trying to automate the data entry of the PieceNumber field. So when you enter a new PO and add items to it, once received. It will add a row to the masterlog table starting at piece number 1 through how ever many pieces we have. We number the pieces based on the items we purchased.(i.e. with Item 1 we purchased 100 pieces. So I would have Item 1 piece 1 through 100.) Then we are able to add the other data to the table. Just trying to reduce some data entry time and avoid some mistakes in the numbering of this field.
Any ideas?
最满意答案
这样的事情是一种非常简单的方法。 您必须有一个名为Numbers的预定义表,其中整数从1开始到您可能拥有的数量很高:
INSERT INTO MasterLog (ItemID, PieceNumber) SELECT Item.ItemID, Numbers.Number FROM Item, Numbers WHERE (Item.ItemID = Forms!Items!ItemID) AND (Numbers.Number <= Item.Quantity) ORDER BY Numbers.Number
如果您想逐个添加这些部分,您可以默认相关表单上的PieceNumber字段。 确保您还默认MasterLog.ItemID:
=Nz(DMax("[PieceNumber]","[MasterLog]","[ItemID] = " & Forms!Items!ItemID), 0) + 1
对于VBA解决方案,请尝试以下方法:
Dim db As Database Dim strSQL As String Dim frm As Form Dim i As Integer Set db = CodeDb() Set frm = Forms!Items If frm!Quantity > 0 Then For i = 1 To frm!Quantity strSQL = "INSERT INTO MasterLog (ItemID, PieceNumber) " & _ "SELECT " & frm!Item & " AS ItemID, " & _ i & " AS PieceNumber" db.Execute strSQL, dbFailOnError Next i End If Set db = Nothing
所有这些都假定一个表单显示当前名为Items的项目。
Something like this would be a very simple way of doing it. You'd have to have a predefined table called Numbers with integers starting from 1 to however high a quantity you might have:
INSERT INTO MasterLog (ItemID, PieceNumber) SELECT Item.ItemID, Numbers.Number FROM Item, Numbers WHERE (Item.ItemID = Forms!Items!ItemID) AND (Numbers.Number <= Item.Quantity) ORDER BY Numbers.Number
If you wanted to add the pieces one by one you could default the PieceNumber field on the related form. Make sure you default MasterLog.ItemID as well:
=Nz(DMax("[PieceNumber]","[MasterLog]","[ItemID] = " & Forms!Items!ItemID), 0) + 1
For a VBA solution try something like this:
Dim db As Database Dim strSQL As String Dim frm As Form Dim i As Integer Set db = CodeDb() Set frm = Forms!Items If frm!Quantity > 0 Then For i = 1 To frm!Quantity strSQL = "INSERT INTO MasterLog (ItemID, PieceNumber) " & _ "SELECT " & frm!Item & " AS ItemID, " & _ i & " AS PieceNumber" db.Execute strSQL, dbFailOnError Next i End If Set db = Nothing
All of these presume a form displaying your current item called Items.
相关问答
更多-
电脑二级考试 是考access 还是VPF[2022-06-08]
access -
如何将数据插入表中? 我怀疑你的身份栏中是否有空白,例如它如下所示: 1 2 5 6 8 9 10 15 ...这可能是一种症状,当数据插入表格时,某些东西会误入歧途。 您是否可以向OP添加有关更新过程的更多信息? 正如评论所说 - 它肯定会是顺序的,但可能存在差距。 如果您需要向自己证明它们是顺序的,您可以添加DateTime字段,例如“WhenUpdated”吗? I think I found out the issue ..Any failed Try to insert is also cons ...
-
这样的事情是一种非常简单的方法。 您必须有一个名为Numbers的预定义表,其中整数从1开始到您可能拥有的数量很高: INSERT INTO MasterLog (ItemID, PieceNumber) SELECT Item.ItemID, Numbers.Number FROM Item, Numbers WHERE (Item.ItemID = Forms!Items!ItemID) AND (Numbers.Number <= Item.Quantity) ORDER BY Number ...
-
Access会记住它在空表上发出的最后一个ID。 要重置自动编号,您必须在清空表后压缩/修复数据库 此外,自动编号是一个长整数,在Access中最高可达2,147,483,647 Access remembers the last ID it gave out even on an empty table. To reset the autonumber you have to compact/repair the database after emptying the table Also the aut ...
-
您不能将ID分配给自动编号字段。 我可能会建议将employeeID字段添加到您的联系人表中,该表中会包含员工ID号。 联系人ID仍然是一个自动编号,所以实质上他们会有两个ID,但他们的employeeID需要存储在不同的字段中。 你可以尝试一些不同的东西,但在某个时候你可能会遇到重复的ID。 为自动编号的客户ID使用单独的表格。 将客户添加到联系人表格中时,将“新”记录“插入”单独的客户ID表中以获取自动编号ID。 如果您要插入员工,只需使用EmployeeID作为联系人ID即可。 所以在混合两个ID系统 ...
-
由于日期值是两倍,整数部分计算一天,您可以使用这个简单的表达式: [Due Date]-[Start Date] 或者,仅限整数天: Fix([Due Date]-[Start Date]) 也就是说,你应该查询这样的任务。 As date values are double with the integer part counting for a day, you can use this simple expression: [Due Date]-[Start Date] or, for inte ...
-
MS Access自动编号问题(MS Access autonumber problem)[2021-10-14]
使用ID字段将newTable设置为AutoNumber(所有字段必须与原始表中的相同 - ID除外)。 将所有数据从originalTable复制到newTable: INSERT INTO newTable SELECT * FROM originalTable 填充数据后,删除originalTable并将newTable重命名为originalTable。 这样就可以保留自动编号中的所有“漏洞”,并且newTable启用了自动编号。 PS始终尝试将外键添加到您的ID。 在这种情况下,即使删除了某些 ... -
自动编号仅用于识别记录,不应该有意义。 如果10和11等对您的应用程序和/或用户来说意味着什么,请使用单独的字段来保存这些数字。 An autonumber is only for identifying the record and should not be meaningful. If 10 and 11 and so on means something for your application and/or the user, have a separate field to hold these ...
-
在Access 2013中报告样式(Report styles in Access 2013)[2022-01-28]
您必须通知您的教师,他们需要更新他们的作业,因为它稍微过时了。 Access中的“报表向导”对话框中的“样式”选项已从Access 2010中的产品中删除。您将在Access 2007中看到它,这可能是您的作业最初起草时的情况。 在Access 2010,2013和2016中,对话框中没有样式选项,因为它已被删除,有利于使用更新的主题用于报表和表单。 You will have to notify your instructor that they will need to update their ass ... -
可能让您感到困惑的是,即使值是一个数字,列表框也总是返回字符串,并且应该这样使用。 此外,DLookup可能会返回Null 。 因此,如果[RequestNumber]是Long(应该是): Private Sub lst_AdminDate1_DblClick(Cancel As Integer) Dim IDx As Variant Dim RequestNum As String DoCmd.OpenForm "Administrative_LeaveCalendar_De ...