|
本帖最后由 fnsmydyang 于 2009-4-7 21:11 编辑
根据刘小军多条件查询改编,出现了一个问题,请教老师们,问题出在哪里,
我要求取得库存信息表中的材质规格最大的一个材料编号(材料编号不等于1000号的),应该只有一笔记录,为什么会取的多笔记录?
调试代码如下:
Private Sub Cmd_Requery_Click()
Dim i As Integer
Dim StrWhere As String
StrWhere = ""
If Not IsNull(Me.Txt_材质) Then
StrWhere = StrWhere & "([材质] = '" & Me.Txt_材质 & "') AND "
End If
If Not IsNull(Me.Txt_规格) Then
StrWhere = StrWhere & "([规格] like '*" & Me.Txt_规格 & "*') AND "
End If
If Len(StrWhere) > 0 Then
StrWhere = StrWhere & "(Max(材料编号) not like '*-1000') AND "
StrWhere = Trim(Left(StrWhere, Len(StrWhere) - 5))
Dim db As DAO.Database
Dim RS As DAO.Recordset
Dim RS1 As DAO.Recordset
Set db = DAO.OpenDatabase(CurrentProject.Path & "\数据库.mdb")
Set RS = db.OpenRecordset("SELECT 材质,规格, Max(材料编号) AS 截止编号 FROM 库存信息 GROUP BY 材质,规格,材料编号 HAVING " & StrWhere & "")
RS.MoveLast
RS.MoveFirst
MsgBox RS.RecordCount
MsgBox RS(2)
db.Close
Set RS = Nothing
End If
End Sub |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|