把Stry改为:
stry = "select * from information where 学号= '" & Text1.Text & "' or 姓名= '" & Text2.Text & "' or班级='" & Text3.Text & "' or 年龄='" & Text4.Text & "'or 性别='" & Text5.Text & "'"

解决方案 »

  1.   

    鎶婏汲锝旓綊锝欐敼涓猴細
    stry = "select * from information where 瀛﹀彿= '" & Text1.Text & "'銆€or 濮撳悕锛濄€€'" & Text2.Text & "'銆€or鐝骇锛?" & Text3.Text & "'銆€or銆€骞撮緞锛?" & Text4.Text & "'or銆€鎬у埆锛?" & Text5.Text & "'"
      

  2.   

    如果年龄是数值型字段,那么把'" & Text4.Text & _"'的单引号去掉
      

  3.   

    "'or班级='" & Text3.Text & _
    "'or年龄='" & Text4.Text & _
    "'or性别='" & Text5.Text & "'"
    是否应该改成这样,在or后要加空格
    "'or 班级='" & Text3.Text & _
    "'or 年龄='" & Text4.Text & _
    "'or 性别='" & Text5.Text & "'"
      

  4.   

    作  者:  olianan (剑琴)  
    对我成见满大的哦!
      

  5.   

    你最好用Debug.print将查询字符串显示出来看一下,你上面的语句or前面后面都没有空格,另外注意一下数据库中的字段是否是字符串类型的,如果不是就不需要用单引号括起来。
      

  6.   

    各位大哥我是想在5个文本框中只要其中一个有输入就可查询!可stry = "select * from information" & _
    " where  学号= '" & Text1.Text &"'"就可以查询一旦改为stry = "select * from information" & _
    " where  学号= '" & Text1.Text & _
     Or "姓名='" & Text2.Text & "'"就提示查询表达式错误!
      

  7.   

    Private Sub GetWhere(strW As String, ByVal strCon As String, ByVal strField As String)
        If strCon <> "" Then
            If strW = "" Then
                strW = strField & "='" & strCon & "'"
            Else
                strW = strW & " AND " & strField & " ='" & strCon & "'"
            End If
        End If
    End Sub
    ==================
        Dim strWhere As String
        Dim strSql As String
        strWhere = ""
        GetWhere strWhere, Me.Text1.Text, "学号"
        GetWhere strWhere, Me.Text2.Text, "姓名"
        GetWhere strWhere, Me.Text3.Text, "班级"
        GetWhere strWhere, Me.Text4.Text, "年龄"
        GetWhere strWhere, Me.Text5.Text, "性别"    strsql="select * from information"
        if strwhere<>"" then
            strsql=strsql & " where " & strwhere
        end if=============================
    试试看
      

  8.   

    stry = "select * from information" & _
    " where  学号= '" & trim(Text1.Text) & _
    "'or 姓名='" & trim(Text2.Text) & _
    "'or 班级='" & trim(Text3.Text) & _
    "'or 年龄='" & trim(Text4.Text) & _
    "'or 性别='" & trim(Text5.Text) & "'" & _
    " And True"
      

  9.   

    注意:你的OR的前后都没加空格!对于“各位大哥我是想在5个文本框中只要其中一个有输入就可查询!”,可以如下操作(另一个帖子是同样的问题):Dim stry As String
    stry = "select * from information where 1=1 "
    if trim(Text1.Text)<>"" then
       stry=stry & "and (学号= '" & Text1.Text &"' "
    end if
    if trim(Text2.Text)<>"" then
       stry=stry & "or 姓名='" & Text2.Text &"' "
    end if
    最后:if instr(stry,"and")>0 then
       stry=stry & ")"
    end if
      

  10.   

    根据字段的类型设置,字符型的要转为 "'" & Text2.Text & "'"
                        数字型的要转为 Text2.Text(无需引号)
                        逻辑型也要转为true,false最好:
    dim number,name,class as string
    dim sex as boolean
    dim old as interger
    number=cstr(text1.text)
    name=cstr(text2.text)
    class=cstr(text3.text)
    old =cint(text4.text)
    if text5.text=1 then 
      sex=true
    else
      sex=false
    endif
    stry = "select * from information" & _
    " where  学号= '" & number & _
    "'or 姓名='" & name & _
    "'or 班级='" & class & _
    "'or 年龄=" & old & _
    " or 性别=" & sex