Private Sub Command1_Click()
Dim str As String
str = vbNullString
If Check1.Value = vbChecked Then
str = "field1=" & Text1.Text
End If
If Check2.Value = vbChecked Then
If Len(str) > 0 Then
str = " and field2=" & Text2.Text
Else
str = "field2=" & Text2.Text
End If
End If
If Check3.Value = vbChecked Then
If Len(str) > 0 Then
str = " and field3=" & Text3.Text
Else
str = "field3=" & Text3.Text
End If
End If
str = "select * from mytable where " & str
'...
End Sub
Dim str As String
str = vbNullString
If Check1.Value = vbChecked Then
str = "field1=" & Text1.Text
End If
If Check2.Value = vbChecked Then
If Len(str) > 0 Then
str = " and field2=" & Text2.Text
Else
str = "field2=" & Text2.Text
End If
End If
If Check3.Value = vbChecked Then
If Len(str) > 0 Then
str = " and field3=" & Text3.Text
Else
str = "field3=" & Text3.Text
End If
End If
str = "select * from mytable where " & str
'...
End Sub
解决方案 »
- 类型不匹配的问题
- tol = 0#<BR> 是什么意思?
- 帮我看下代码,关于SHGetIDListFromPath,比较少见,不懂回答看了赚点知识也不错。
- 应广大爱好者的要求,现再次开贴发放打印预览控件。
- Data Report如何只打印指定的某条记录
- 为什么记录是空的时候,下移记录,而text里的值不变,是原来的值?为什么记录是空的时候,下移记录,而text里的值不变,是原来的值?
- 用FOR循环 循环条件是时间date
- 在VB中数据环境一进入命令层的操作就退出VB,为什么?
- 急!关于数据库连接字符串,odbc连接问题!
- [求助]VB6排座位问题
- 怎么在程序响应时间让鼠标箭头变成沙漏?
- 程序在一个do while(1).... doevents loop 里运行,一般情况下运行正常,但是有时候用鼠标点界面的任何按钮都没有反应,过了几分钟才有反
稍微改下呵呵
Private Sub Command1_Click()
Dim str As String
str = vbNullString
If Check1.Value = vbChecked Then
str = "field1=" & Text1.Text
End If
If Check2.Value = vbChecked Then
str = " and field2=" & Text2.Text End If
If Check3.Value = vbChecked Then
str = " and field3=" & Text3.Text End If
str = "select * from mytable where 1=1 " & str
'...
End Sub
稍微改下呵呵
Private Sub Command1_Click()
Dim str As String
str = vbNullString
If Check1.Value = vbChecked Then
str = " and field1=" & Text1.Text
End If
If Check2.Value = vbChecked Then
str = " and field2=" & Text2.Text End If
If Check3.Value = vbChecked Then
str = " and field3=" & Text3.Text End If
str = "select * from mytable where 1=1 " & str
'...
End Sub
Private Sub Command1_Click()
Dim str As String
str = vbNullString
If Check1.Value = vbChecked Then
str = " and field1=" & Text1.Text
End If
If Check2.Value = vbChecked Then
str = str & " and field2=" & Text2.Text
End If
If Check3.Value = vbChecked Then
str = str & " and field3=" & Text3.Text
End If
str = "select * from mytable where 1=1 " & str
'...
End Sub
========================================
为什么不是str="" ?
我认为vbNullString不是这么用的
MSDN:
vbNullString 值为 0 的字符串 用来调用外部过程;与长度为零的字符串 ("") 不同