| 发表于:2007-09-25 09:52:347楼 得分:15 |
'以下代码在access2000+vb6调试通过,数据库test.mdb中表tb字段-bh private sub command1_click() dim db as adodb.connection dim rs as adodb.recordset dim tempbh as string, tempyear as string, bhnum as string set db = new adodb.connection db.cursorlocation = aduseclient db.connectionstring = "provider=microsoft.jet.oledb.4.0; " + "data source= " + app.path + "\test.mdb " db.open "data source= " + app.path + "\test.mdb; " set rs = new adodb.recordset rs.open "tb order by bh ", db, adopenkeyset, adlockoptimistic if rs.recordcount = 0 then '第一次建立编号 bhnum = "xf " & format(date, "yyyymmdd ") & "-0001 " else tempdate = format(date, "yyyymmdd ") 'msgbox tempdate if rs.state = adstateopen then rs.close rs.open "select * from tb where bh like 'xf '+ ' " & tempdate & " '+ '% ' order by bh ", db, adopendynamic, adlockoptimistic 'msgbox rs.recordcount if rs.recordcount > 0 then '当天有记录时 if rs.state = adstateopen then rs.close rs.open "tb order by bh ", db, adopendynamic, adlockoptimistic rs.movelast tempyear = left(rs!bh, 11) '左边11位 tempbh = right(rs!bh, 4) + 1 '右边4位 if len(tempbh) = 1 then tempbh = "000 " & tempbh end if if len(tempbh) = 2 then tempbh = "00 " & tempbh end if if len(tempbh) = 3 then tempbh = "0 " & tempbh end if msgbox tempbh bhnum = tempyear & tempbh else bhnum = "xf " & format(date, "yyyymmdd ") & "-0001 " '当天初始临时编号 end if end if rs.addnew rs!bh = bhnum rs.update rs.close set db = nothing end sub | | |
|