单击 MS Access 表单中的按钮时出现语法错误

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

我正在创建一个数据库,我想为每个条目生成一个 UniqueReference - 格式为 YY-0000。在表单中,我放置了一个带有以下代码的按钮,但它出现语法错误,我不知道如何修复它。

Private Sub Command39_Click()

Dim vLast As Variant
Dim iNext As Integer

vLast = DMax("[UniqueReference]", "[ScammerInfo]", "[UniqueReference]" & Format([DateCreated], "yy\*\'"))
If IsNull(vLast) Then
    iNext = 1
Else
    iNext = Val(Right(vLast, 4)) + 1
End If

Me![UniqueReference] = Format([txtDateCreated], "yy") & "-" & Format(Next, "0000")

End Sub

我用谷歌搜索过,但我发现的任何东西对我来说都没有任何意义

vba forms ms-access
1个回答
0
投票

尝试使用这一行:

Me![UniqueReference].Value = Format([DateCreated], "yy\-") & Format(Nz(DMax("[UniqueReference]", "[ScammerInfo]", "[UniqueReference] Like '" & Format([DateCreated], "yy\-????") & "'")) + 1, "0000")
© www.soinside.com 2019 - 2024. All rights reserved.