只检查控件是真还是非空。 To make it easier, name the screen controls the same as the underlying columns. Then iterate the controls on the screen. Attach code to your Search button, something like this: ''VARS dim sqlStr as string, ctl as Control sqlStr = "" ''ITERATE CONTROLS for each ctl in Me.Controls if ctl.ControlType = acCheckBox then if ctl = True then sqlStr = sqlStr & ctl.Name & ", " endif elseif ctl.ControlType = acTextBox then if not isnull(ctl) then sqlStr = sqlStr & ctl.Name & ", " endif endif next ctl ''NO CONTROLS CHOSEN OR COMPLETED if sqlStr = "" then msgbox "Please select a box",,"System Name" exit sub endif ''TRIM AND DROP TRAILING COMMA sqlStr = trim(sqlStr) sqlStr = left(sqlStr,len(sqlStr)-1) ''SHOW DATA sqlStr = "SELECT " & sqlStr & " FROM Table WHERE blah blah; Me.Subform.RecordSource = sqlStr Note: this code doesn''t build any WHERE criteria into the SQL statement - it just checks if the control is True or Not Null. 为简化起见,请将屏幕控件命名为基础列。然后迭代屏幕上的控件。将代码附加到您的搜索按钮,如下所示:''VARS 将sqlStr作为字符串,ctl作为控件 sqlStr ="" 为I.Controls中的每个ctl设置ITERATE CONTROLS 如果ctl.ControlType = acCheckBox则如果ctl = True则 sqlStr = sqlStr& ctl.Name& "," endif elseif ctl.ControlType = acTextBox然后如果不是isnull(ctl)那么 sqlStr = sqlStr& ctl.Name& "," endif endif 下一个ctl ''没有控制选择或完成如果sqlStr =""然后 msgbox请选择一个方框,系统名称退出子页 ''TRIM AND DROP TRAILING COMMA sqlStr = trim(sqlStr) sqlStr = left(sqlStr,len(sqlStr)-1)''显示数据 sqlStr =" SELECT" &安培; sqlStr& " FROM表WHERE等等等等; Me.Subform.RecordSource = sqlStr 注意:此代码没有在SQL 语句中构建任何WHERE标准 - 它只检查控件是True还是No Null。 To make it easier, name the screen controls the same as the underlying columns. Then iterate the controls on the screen. Attach code to your Search button, something like this: ''VARS dim sqlStr as string, ctl as Control sqlStr = "" ''ITERATE CONTROLS for each ctl in Me.Controls if ctl.ControlType = acCheckBox then if ctl = True then sqlStr = sqlStr & ctl.Name & ", " endif elseif ctl.ControlType = acTextBox then if not isnull(ctl) then sqlStr = sqlStr & ctl.Name & ", " endif endif next ctl ''NO CONTROLS CHOSEN OR COMPLETED if sqlStr = "" then msgbox "Please select a box",,"System Name" exit sub endif ''TRIM AND DROP TRAILING COMMA sqlStr = trim(sqlStr) sqlStr = left(sqlStr,len(sqlStr)-1) ''SHOW DATA sqlStr = "SELECT " & sqlStr & " FROM Table WHERE blah blah; Me.Subform.RecordSource = sqlStr Note: this code doesn''t build any WHERE criteria into the SQL statement - it just checks if the control is True or Not Null. 这篇关于高级查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 23:56