Office中国论坛/Access中国论坛

标题: [求助]如何自动产生编号 [打印本页]

作者: liulubing    时间: 2006-8-23 18:21
标题: [求助]如何自动产生编号
有这样一个格式的编号,请问各位版主如何自动产生.LD06PE0575.


其中LD和PE是固定的,06是年份,0575是流水号,也就是说顺序下排0576,0577等等.


就是说双击后可以自动按前面的流水号自己产生,比如第一个是LD06PE0575.第二个就是LD06PE0576.


各位谢谢了,在此拜托了.


我的写法是,但是不对.ORDERNO是字段名,O-外贸订货单头是表名.


Dim cn1 As New ADODB.Connection
  Dim com As New ADODB.Command
  Dim rec1 As New ADODB.Recordset
  Dim strtemp, a, b As String
     DoCmd.GoToRecord , , acNewRec
     Set cn1 = CurrentProject.Connection
     Set com.ActiveConnection = cn1
     com.CommandText = "select max(ORDERNO) as ORDERNO  from [O-外贸订货单头]"
     Set rec1 = com.Execute
     strtemp = rec1("ORDERNO")
        strtemp = 'LD' + Right(Year(DATE), 2) +'PE'+ Right((Right(strtemp, 4) + 1), 4)
     Me.OrderNo = strtemp

[此贴子已经被作者于2006-8-24 7:37:42编辑过]


作者: liulubing    时间: 2006-8-30 22:14
     问题已解决,代码如下
     Dim cn1 As New ADODB.Connection
     Dim com As New ADODB.Command
     Dim strtemp As String
     Set cn1 = CurrentProject.Connection
     Set com.ActiveConnection = cn1
     If IsNull(Me.OrderNo) Then
     com.CommandText = "select 'LD'+right(year(getdate()),2)+'PI'+replicate('0',4-len(cast(cast(right(isnull(max(orderno),'0000'),4) as int) as nvarchar(4))))+cast(right(isnull(max(orderno),'0000'),4)+1 as nvarchar(4)) as orderno from [O-外贸订货单头] "
     Set rec1 = com.Execute
      Me.OrderNo = rec1("orderno")
     DoCmd.RunMacro ("save")
     Else
     Me.OrderNo.Locked = True
     End If




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3