Custom user autonumber

自作多情 提交于 2019-12-02 09:28:26

You can use the BeforeInsert event of the form:

Me!AutoNumber.Value = Format(Val(Nz(Right(DMax("[AutoNumber]", "[YourTable]"), 3), 0)) + 1, "\D000")

That is 1 way to do this is create a function to handle the autonumber problem u had

create function NextAutoNumber() 
returns char(4) 
as 
begin 
    declare @lastval char(4) 
    set @lastval = (select max(autoNumber) from table) 
    if @lastval is null set @lastval = 'D001' 

    declare @i int set @i = right(@lastval,3) + 1 return 'C' + right('00' + convert(varchar(10),@i),3) 
end

like this you can just call the function anytime and insert the auto number you need for the record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!