假设你表中的编号字段名曰编号,你的表名名曰tbname,你的窗体上有两个控件,其一名曰前缀,其二名曰后缀,你想得到符合前缀和后缀的自动编号,则:
function 自动编号(str0 as string,str1 as string) as string
dim str as string
str=nz(dmax("编号","tbname","left(编号,1)='" & str0 & "' and mid(编号,8,2)='" & str1 & "' and mid(编号,2,6)='" & fromat(date(),"yymmdd")),str0 & fromat(date(),"yymmdd") & str1 & "-0000")
str=left(str,10) & format(Right(str,4)+1,"0000")
if nz(str0,"")="" or nz(str1,"")="" then
自动编号=""
else
自动编号=str
end if
end function