Sub Orderid_auto() Dim rs As New ADODB.Recordset 'Dim imonth, idmin, idmax, b As String imonth = Right(Year(Date), 2) & Format(Month(Date), "00") idmin = imonth & "000" idmax = imonth & "999" ISEL = "select max(订单ID) from 订单 where 订单ID > '" & idmin & "' and 订单ID < '" & idmax & "'" rs.Open ISEL, CurrentProject.Connection, 1, 1 Dim b As Long If IsNull(rs(0)) Then b = idmin Else b = rs(0) rs.Close [订单ID] = Format((b + 1), "0000000") '[订单ID] = Format("050704", "000000") End Sub ======= 修改为 Sub Orderid_auto() Dim rs As New ADODB.Recordset Dim imonth as string, idmin as string , b As String imonth = Right(Year(Date), 2) & Format(Month(Date), "00") idmin = imonth & "000" ISEL = "select max(订单ID) from 订单" rs.Open ISEL, CurrentProject.Connection, 1, 1 Dim b As Long If IsNull(rs(0)) Then b = idmin Else b = imonth & right(rs(0),3) rs.Close [订单ID] = Format((b + 1), "0000000") End Sub
[此贴子已经被作者于2007-5-16 2:08:51编辑过] |