我的代码出了问题。
我的MS Access数据库需要在新的一个月或一年的开始时重置序列号字段。
但是,在测试数据库时,它可以正常工作,直到我到达第10条记录,然后收到一个重复的值警告。
我完全搞不懂我哪里出了问题。
请帮帮忙?代码粘贴在下面:
Private sub form_beforeinsert(Cancel as integer)
dim vlast as variant
dim invnext as integer
me.invyear = format(date,"yyyy") & format(date, "mm")
vlast = dmax("SeriesNumber", "invoice", "InvYear='" & Me.invyear.value & "'")
if isnull(vlast) then
    invnext = 1
else
    invnext = vlast + 1
end if
me.seriesnumber = invnext
me.invoicenumber = format(date, "yyyy") & "-" & Format(date, "mm") & "-" Me.SeriesNumber
End Sub 发布于 2022-03-23 14:36:49
这是因为你似乎把所有的东西都存储成文字。因此,转换为一个数字来检索数值最大值:
    vlast = DMax("Val([SeriesNumber])", "invoice", "InvYear='" & Me!invyear.Value & "'")https://stackoverflow.com/questions/71588679
复制相似问题