In the text1.KeyUp event,filter the Enter key,and write the code like this:
set rs=cn.execute("Select name from table where ID='" & text1 & "'")
if not rs.eof then text2=rs(0) & ""

解决方案 »

  1.   

    in text1.KeyUp event,filter the Enter key,and write code like this:
    set rs=cn.execute("Select name from table where ID='" & text1 & "'"
    if not rs.eof then text2=rs(0) &""
      

  2.   

    楼上的方法可以马上更新,但是就是每次按键都要查数据库。
    也可以在text1的validate事件里放入上面的代码,这样就只有在text失去焦点前才查找。
      

  3.   

    在第一个TEXT框中捕捉KEYUP事件,处理回车健作为输入结束的标志,然后根据输入信息进行查询。对于第二个TEXT框,将由第一个TEXT框输入所得到的RECORDSET作为数据源进行梆定,并且指定所需要查询的DATAFIELD。这样第二个TEXT框的内容可以自动关联。如此还有个好处就是:如果所查询的数据量不大,可以一次将所有需要的数据RECORDSET取回,然后使用SEEK或FIND方法在本地RECORDSET当中进行查询,速度极快,而且使用上述方法可以自动对于进行显示,不妨试试。