在第一个text的keypress事件里面
判断KeyAscii是否vbKeyReturn
写检索用户名的sql语句
然后输出到第二个text就行了

解决方案 »

  1.   

    写检索用户名的sql语句sql怎么写
      

  2.   

    再userid得keypress中,判断是否是回车,是否为空
    然后
    "select username from table where userid='"&txtuserid.text&"'"
    if not adors.eof then
     txtusername.text=adors("username")
    else
     msgbox ....
    end if
      

  3.   

    建议用户id和用户名用combo,窗体启动时填充。
    输入id时动态搜索用户名combo即可。
    Private Declare Function SendMessage Lib _
    "user32" Alias "SendMessageA" (ByVal hWnd _
    As Long, ByVal wMsg As Long, ByVal wParam _
    As Long, lParam As Any) As Long
    Private Const CB_FINDSTRING = &H14Cprivate sub form1_load()
    dim cnn as adodb.connection, rs as adodb.recordset
    set cnn = new adodb.connection
    cnn.open yourcnnstring
    set rs = new adodb.recordset
    set rs = cnn.execute("select * form Password")
    comboID.style = 0
    comboName.style = 2
    do until rs.eof
    comboid.additem rs!id
    comboname.additem rs!name
    rs.movenext
    loop
    end subPrivate Sub ComboID_KeyPress(KeyAscii As Integer)
    Call ComboIncrementalSearch(ComboID, KeyAscii)
    comboName.listindex = comboID.listindex
    End SubPublic Sub ComboIncrementalSearch(cbo As _
    ComboBox, KeyAscii As Integer)
    Static dTimerLast As Double
    Static sSearch As String
    Static hWndLast As Long
    Dim nRet As Long
    Const MAX_KEYPRESS_TIME = 0.5
    ' Weed out characters that are not scanned
    If (KeyAscii < 32 Or KeyAscii > 127) _
    Then Exit Sub
    If (Timer - dTimerLast) < _
    MAX_KEYPRESS_TIME And hWndLast = _
    cbo.hWnd Then
    sSearch = sSearch & Chr$(KeyAscii)
    Else
    sSearch = Chr$(KeyAscii)
    hWndLast = cbo.hWnd
    End If
    ' Search the combo box
    nRet = SendMessage(cbo.hWnd, _
    CB_FINDSTRING, -1, ByVal sSearch)
    If nRet >= 0 Then
    cbo.ListIndex = nRet
    End If
    KeyAscii = 0
    dTimerLast = Timer
    End Sub
    end sub