vb操作access多条件模糊综合查询疑问
一运行就提示操作符丢失,PrivateSubCommand7_Click()'模糊查找操作ser="where1=1"IfOption1.Value=TrueThense...
一运行就提示操作符丢失,
Private Sub Command7_Click()
'模糊查找操作
ser = " where 1=1 "
If Option1.Value = True Then
ser = ser & " and 日期 between " & Chr(35) & DTPicker3.Value & Chr(35) & " and " & Chr(35) & DTPicker4.Value & Chr(35) & ""
End If
'如果加工类别被选中
If Check1.Value = 1 Then
ser = ser & " and 加工类别 like '%" & Trim(Combo9.Text) & "%'"
End If
'如果G编号被选中
If Check2.Value = 1 Then
ser = ser & " and G编号 like '%" & Trim(Text20.Text) & "%'"
End If
'如果F编号被选中
If Check3.Value = 1 Then
ser = ser & " and F编号 like '%" & Trim(Text21.Text) & "%'"
End If
'如果工程名称被选中
If Check4.Value = 1 Then
ser = ser & " and 工程名称 like'%" & Trim(Text22.Text) & "%'"
End If
'如果工令号被选中
If Check5.Value = 1 Then
ser = ser & " and 工令号 like'%" & Trim(Text23.Text) & "%'"
End If
'如果备注被选中
If Check6.Value = 1 Then
ser = ser & " and 备注 like'%" & Trim(Text24.Text) & "%'"
End If
'如果状态被选中
If Check7.Value = 1 Then
ser = ser & " and 状态 like'%" & Trim(Combo7.Text) & "%'"
End If
'如果发运被选中
If Check8.Value = 1 Then
ser = ser & " and 发运 like'%" & Trim(Combo8.Text) & "%'"
End If
Adodc2.RecordSource = "select * from 计划内 where" & ser & "order by val(序号)"
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
Adodc3.RecordSource = "select sum(数量)as 数量,sum(已完成)as 已完成,sum(未完成)as 未完成 from 计划内 where " & ser
Adodc3.Refresh
Label34.Caption = "共查询出" & Space(1) & Adodc2.Recordset.RecordCount & Space(1) & "条结果" & Space(2) & _
"合计数量:" & Space(1) & Adodc3.Recordset.Fields(0) & Space(1) & "根" & Space(2) & _
"合计已完成:" & Space(1) & Format(Adodc3.Recordset.Fields(1), "0") & Space(1) & "根" & Space(2) & _
"合计未完成:" & Space(1) & Format(Adodc3.Recordset.Fields(2), "0") & Space(1) & "根"
Else
Label34.Caption = "共查询出" & Space(1) & 0 & Space(1) & "条结果" & Space(2) & _
"合计数量:" & Space(1) & 0 & Space(1) & Space(1) & "根" & Space(2) & _
"合计已完成:" & Space(1) & 0 & Space(1) & "根" & Space(2) & _
"合计未完成:" & Space(1) & 0 & Space(1) & "根"
End If
End Sub 展开
Private Sub Command7_Click()
'模糊查找操作
ser = " where 1=1 "
If Option1.Value = True Then
ser = ser & " and 日期 between " & Chr(35) & DTPicker3.Value & Chr(35) & " and " & Chr(35) & DTPicker4.Value & Chr(35) & ""
End If
'如果加工类别被选中
If Check1.Value = 1 Then
ser = ser & " and 加工类别 like '%" & Trim(Combo9.Text) & "%'"
End If
'如果G编号被选中
If Check2.Value = 1 Then
ser = ser & " and G编号 like '%" & Trim(Text20.Text) & "%'"
End If
'如果F编号被选中
If Check3.Value = 1 Then
ser = ser & " and F编号 like '%" & Trim(Text21.Text) & "%'"
End If
'如果工程名称被选中
If Check4.Value = 1 Then
ser = ser & " and 工程名称 like'%" & Trim(Text22.Text) & "%'"
End If
'如果工令号被选中
If Check5.Value = 1 Then
ser = ser & " and 工令号 like'%" & Trim(Text23.Text) & "%'"
End If
'如果备注被选中
If Check6.Value = 1 Then
ser = ser & " and 备注 like'%" & Trim(Text24.Text) & "%'"
End If
'如果状态被选中
If Check7.Value = 1 Then
ser = ser & " and 状态 like'%" & Trim(Combo7.Text) & "%'"
End If
'如果发运被选中
If Check8.Value = 1 Then
ser = ser & " and 发运 like'%" & Trim(Combo8.Text) & "%'"
End If
Adodc2.RecordSource = "select * from 计划内 where" & ser & "order by val(序号)"
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
Adodc3.RecordSource = "select sum(数量)as 数量,sum(已完成)as 已完成,sum(未完成)as 未完成 from 计划内 where " & ser
Adodc3.Refresh
Label34.Caption = "共查询出" & Space(1) & Adodc2.Recordset.RecordCount & Space(1) & "条结果" & Space(2) & _
"合计数量:" & Space(1) & Adodc3.Recordset.Fields(0) & Space(1) & "根" & Space(2) & _
"合计已完成:" & Space(1) & Format(Adodc3.Recordset.Fields(1), "0") & Space(1) & "根" & Space(2) & _
"合计未完成:" & Space(1) & Format(Adodc3.Recordset.Fields(2), "0") & Space(1) & "根"
Else
Label34.Caption = "共查询出" & Space(1) & 0 & Space(1) & "条结果" & Space(2) & _
"合计数量:" & Space(1) & 0 & Space(1) & Space(1) & "根" & Space(2) & _
"合计已完成:" & Space(1) & 0 & Space(1) & "根" & Space(2) & _
"合计未完成:" & Space(1) & 0 & Space(1) & "根"
End If
End Sub 展开
1个回答
展开全部
Adodc2.RecordSource = "select * from 计划内 where" & ser & "order by val(序号)"
ser开头已经有一个where了。
建议你看一下到底把行来源设成了什么。可以逐步调试,运行到这里时,在立即窗口输入:
? "select * from 计划内 where" & ser & "order by val(序号)"
然后在立即窗口回车,这样可以清楚看到结果
ser开头已经有一个where了。
建议你看一下到底把行来源设成了什么。可以逐步调试,运行到这里时,在立即窗口输入:
? "select * from 计划内 where" & ser & "order by val(序号)"
然后在立即窗口回车,这样可以清楚看到结果
追问
我已经解决了,就是下面的where惹的祸,哈哈,谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询