Set p = New Recordset
 p.LockType = adLockOptimistic
 p.CursorType = adOpenStatic
 p.Open "select*  from a ", cnn1
 rs = "准考证号=" & "'" & a2 & "'" & " and " & "考生姓名=" & "'" & _
     a3 & "'" & " and " & "考试项目=" & "'" & a4 & "'"
 p.Filter = rs
    
   If p.EOF = False Then
     a1 = p.Fields("考生姓名").Value
     MsgBox a1, vbInformation小弟初涉VB,求详解

解决方案 »

  1.   

    估计是
    取出表A中 准考证号= a2 并且 考生姓名= a3 并且 考试项目= a4
    的样的数据 
    然后把 考生姓名 这个值 给 a1  
      

  2.   

    没有啥意思.
    条件是 准考证号,考生姓名,考试项目
    结果是 考生姓名.若查不到,a1="";查到了,a1=a3
    既然已知姓名是a3,还查姓名作甚...
      

  3.   

    Set p = New Recordset 
    p.LockType = adLockOptimistic 
    p.CursorType = adOpenStatic 
    p.Open "select*  from a ", cnn1 '这里查询数据库所有记录rs = "准考证号=" & "'" & a2 & "'" & " and " & "考生姓名=" & "'" & _ 
        a3 & "'" & " and " & "考试项目=" & "'" & a4 & "'" p.Filter = rs '这里给记录集设置过滤器,只保留符合条件的记录
        
      If p.EOF = False Then '如果有符合条件的记录,则显示
        a1 = p.Fields("考生姓名").Value 
        MsgBox a1, vbInformation 实际上,完全可以:
    Set p = New Recordset 
    p.LockType = adLockOptimistic 
    p.CursorType = adOpenStatic 
    p.Open "select*  from a Where 准考证号=" & "'" & a2 & "'" & " and " & "考生姓名=" & "'" & _ 
        a3 & "'" & " and " & "考试项目=" & "'" & a4 & "'", cnn1  If p.EOF = False Then '如果有符合条件的记录,则显示
        a1 = p.Fields("考生姓名").Value 
        MsgBox a1, vbInformation
      End If