Office中国论坛/Access中国论坛
标题:
求助:截取查询最大值
[打印本页]
作者:
siaele
时间:
2011-12-20 21:56
标题:
求助:截取查询最大值
先谢谢坛上的热心朋友. 我的问题见附图:
[attach]47741[/attach]
附件在这里.
[attach]47742[/attach]
作者:
Henry D. Sy
时间:
2011-12-20 22:42
Private Sub Command2_Click()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim strWhar As String
Dim sSQL As String
Dim rsBom As String
Set cnn = CurrentProject.Connection
If IsNull(Me.BOM) Then
MsgBox "请输入BOM"
Exit Sub
ElseIf Len(Me.BOM) < 4 Then
MsgBox "请输入4位以上的BOM"
Exit Sub
End If
strwhat = Left(Me.BOM, 4)
sSQL = "select bom from 表1 where left(bom,4)='" & strwhat & "' order by id desc"
rs.Open sSQL, cnn, adOpenKeyset, adLockReadOnly
If rs.RecordCount <= 0 Then
Me.NewBOM = Me.BOM
Else
rsBom = rs.Fields(0)
Select Case Len(rsBom)
Case 4
Me.NewBOM = rsBom & "-1"
Case Is > 4
Me.NewBOM = Split(rsBom, "-")(0) & "-" & Val(Split(rsBom, "-")(1)) + 1
End Select
End If
rs.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
复制代码
作者:
Henry D. Sy
时间:
2011-12-20 22:58
注意:
表1中的bom大小号要与id的大小排序成正比!
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3