举个例子
如果FORM1里面有userID,password,info等复选框
分别为form1中间的字段
那么在form2中
SQL="SELECT id"
if request.form("userID")="on"
SQL = SQL & ",userID"
end
if request.form("password")="on"
SQL=SQL & ",password"
end
if request.form("info")="on"
SQL=SQL & ",info"
end
SQL=SQL + "FROM table WHERE ...."
就可以了,
对不起,昨天的程序还是有一个地方忽略了,
改过如下:
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
strSelect=""
For i = 0 To (控件数 - 1)
If Check(i).Value = True Then
strSelect = strSelect & Check(i).Caption & ","
End If
Next i
'去掉最后一个逗号
strSelect = Left(strSelect, (Len(strSelect) - 1))
我的程序漏了一条,下面是改过的
'在form2中定义一个字符串型的全局变量,
Dim strSelect as String
将form2中的各复选框作成一个控件数组,然后添加如下代码
'Form2中
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
strSelect=""
For i = 0 To (控件数 - 1)
If Check(i).Value = True Then
strSelect = strSelect & "," & Check(i).Caption
End If
Next i
End Sub
在form1的activate事件中将Adodc1的数据源设为如下代码:
Adodc1.RecordSource="Select " & form2.strSelect & " from 表名"'
不用SQL语句,用datagrid控件的columns对象的visible属性
设置check为控件数组,按表中字段顺序一一对应设置check,caption
dim i as integer
在form2中添加代码
for i=0 to 控件数组数目
if form1.check(i).value=true then
datagrid1.columns(i).visible=false
else
datagrid1.columns(i).visible=true
end if
next i
'在form2中定义一个字符串型的全局变量,
Dim strSelect as String
将form2中的各复选框作成一个控件数组,然后添加如下代码
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
For i = 0 To (控件数 - 1)
If Check(i).Value = True Then
strSelect = strSelect & ","
End If
Next i
'去掉最后一个逗号
strSelect = Left(strSelect, (Len(strSelect) - 1))
End Sub
在form1的activate事件中将Adodc1的数据源设为如下代码:
Adodc1.RecordSource="Select " & form2.strSelect & " from 表名"'
dim sel as string
dim isselonefld as bool'为true,说明已经选择了至少一个字段,着要在后继字段前加上
‘ ” ,“号
sel="select "
isselonefld=false
if check1.value=true then
sel=sel&"field1"
isselonefld=true
endif
if check2.value=true then
if isselonefld=true then
sel=sel & ",field2"
else
sel=sel&"field2"
isselonefld=true
endif
endif
if check3.value=true then
if isselonefld=true then
sel=sel & ",field2"
else
sel=sel&"field3"
isselonefld=true
endif
endif
if not isselonefld then
msgbox"至少选择一个字段”
else
sel=sel&" from tablename where...order by..."
adodc1.recordsouse=sel
adodc1.refresh
endif