如何在 MS Access 中将文本框“数字”与下一个数字连接

问题描述 投票:0回答:1

我有大量数据正在被放入不存在的访问数据库中。目前正在使用的一些数字是无法保留的,问题是它们实际上是文本字符串。格式:1.1.1.1、1.1.1.1.2、1.1.1.1.3、1.1.1.1.3.1 等这些字符串的深度可达九个数字。

最终用户希望能够使用新记录“自动填充”字符串中的下一个数字。目前我什至不确定这是否有可能。任何新记录都将是具有已确定编号的现有记录的子记录,因此我需要表单来查看主表单编号,然后在子表单记录中添加下一个数字。

例如为了保持简单:

主表单 ID# 为 1.1.1 子表单 ID# 需要为 1.1.1.1 子表单上的下一条记录是 1.1.1.2 等等

我的子表单与我的主表单相关,并且我创建了一个用于连接数据的字段。我想我必须在该字段的子表单中设置表达式,但是我不确定如何创建一个自动编号以进入公式。我确信这很简单,但我没有找到它。

ms-access concatenation autonumber
1个回答
0
投票

统计子表单的记录来计算数量。

在子窗体的 OnCurrent 事件中运行这样的代码:

Dim Records     As DAO.Recordset

Dim Count       As Integer
Dim NextNumber  as String

If IsNull(Me!Number.Value) Then
    ' Find the count of child records.
    Set Records = Me!RecordsetClone
    If Records.RecordCount > 0 Then
        Records.MoveLast    
    End If
    Count = Records.RecordCount
    Records.Close
    
    ' Concatenate the main form number, say 1.1.1, and the number of this record, say 2, to
    ' obtain 1.1.1.2 as the next number.
    NextNumber = Me.Parent!Number.Value & "." & CStr(Count)
    ' Assign this next number.
    Me!Number.Value = NextNumber
Else
    ' Number has been assigned previously.
End
© www.soinside.com 2019 - 2024. All rights reserved.