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