Dim sqlselect1 As String
sqlselect1 = ""
If Not ([Combo2] = "" Or IsNull(Combo2)) Then
sqlselect1 = sqlselect1 + " data_main.责任人='" & Forms![operate_main]![Combo2] & "' "
End If
If Not ([Combo4] = "" Or IsNull(Combo4)) Then
sqlselect1 = sqlselect1 + " and data_main.部门代码= '" & Forms![operate_main]![Combo4] & "' "
End If
If Not ([Combo10] = "" Or IsNull(Combo10)) Then
sqlselect1 = sqlselect1 + " and data_main.外协厂家= '" & Forms![operate_main]![Combo10] & "' "
End If
If Not ([Combo30] = "" Or IsNull(Combo30)) Then
sqlselect1 = sqlselect1 + " and data_main.任务号='" & Forms![operate_main]![Combo30] & "' "
End If
Dim dateStr As String
If Not (IsNull(Text52) Or [Text52] = "") Then
Select Case Frame45
Case 1
dateStr = " and data_main.s_date>='" & Forms![operate_main]![Text52] & "' "
Case 2
dateStr = " and data_main.s_date>='" & Forms![operate_main]![Text52] & "' "
End Select
End If
If Not (IsNull(Text54) Or [Text54] = "") Then
Select Case Frame45
Case 1
dateStr = dateStr + " and data_main.e_date<='" & Forms![operate_main]![Text54] & "' "
Case 2
dateStr = dateStr + " and data_main.e_date<='" & Forms![operate_main]![Text54] & "' "
End Select
End If
If Not (IsNull([dateStr]) Or [dateStr] = "") Then
sqlselect1 = sqlselect1 + dateStr
End If
If (IsNull([sqlselect1]) Or [sqlselect1] = "") Then
Forms![operate_main]![data_main].Form.RecordSource = "select * from data_main"
Else
Forms![operate_main]![data_main].Form.RecordSource = "select * from data_main where sqlselect1"
以上的代码是我做一个查询,是想将各种查询条件赋给字符串sqlselect1。然后按“查询”即可将符合条件的记录查询出来。
直接查询,OK,所有的记录都会出来。但我在各控件输入条件后再查询,则系统提示要输入“sqlselect1的参数值”,各控件内的参数无法赋给sqlselect1。调试的时候,显示是最后一句代码有问题。如何解决,代码如何修改。
谢谢!
[此贴子已经被lihao6于2002-5-28 14:31:22编辑过]
|