叶子,我把我写的程序给你看看。 帮我检查一遍。 Function SNNUM(tname, first_char, brief_city) Dim rs, sql, temp_num, insect_num, num, cn, num1, Set rs = myServer.CreateObject("ADODB.Recordset") sql = "select * from "&tname&" where sn like '%"&brief_city&"%' and sn like '%"&first_char&"%' order by ssdate DESC;" '查找同类编号 rs.Open sql, cn, 3, 3 If rs.EOF Then num1 = brief_city &"000000"& first_char '没有同类编号则从000000开始 SNNUM = num1 '返回编号 Else temp_num = mid(rs("sn"), 3,6) + 1 '有的话取得数值部分并加1 if Len(temp_num)=1 then insect_num = "00000" &temp_num '给整数前补0 else if Len(temp_num)=2 then insect_num = "0000"&temp_num else if Len(temp_num)=3 then insect_num = "000"&temp_num else if Len(temp_num)=4 then insect_num = "00"&temp_num else if Len(temp_num)=5 then insect_num = "0"&temp_num else if Len(temp_num)=6 then insect_num = temp_num end if Next SNNUM = brief_city&insect_num&first_char '返回编号 End If End Function
设两个字段,一个是默认的自动编号主键,字段名为system_id,即 1、2、3 ...... 另一个是你的这个编号,字段名为custom_id 于是这样考虑 custem_id = "q" & system_id & "s" 如果要补零,可以另写一个函数
你所需要的编号,看上去也是连续的,完全可以按照通常情况那样使用自动编号字段,在需要使用的地方,可以根据对应关系转换为你需要的格式。 例如 1 - 0 - 000000 - q000000s 2 - 1 - 000001 - q000001s 这样对应转换应该可以吧?