2015-04-26 71 views
1

使用VB 6和adodb連接,當我點擊搜索id時,會出現一個inputbox,當它找到我想要的id時,它會自動將該行的所有數據插入到它們的相應的文本框。搜索數據庫並將其放入文本框

在這裏,我的代碼,在某些時候,它不起作用,我不記得錯誤,但我會在這裏發佈它,當我回到家,感謝您的幫助球員。

Private Sub cmdsearch_Click() 
    findemployee = InputBox("Insert Employee ID") 
    record.Open ("select * from employees where ID='" & findemployee & "'"), conn, 3, 3 

    If record.EOF Then 
     MsgBox "NO" & findemployee & " ID WAS NOT FOUND!", vbCritical + vbOKOnly, "Error Search" 
     Set record = Nothing 
    Else 

     txtemployeeid.Text = record!ID 
     txtlnames.Text = record!lastname 
     txtfnames.Text = record!Firstname 
     txtmnames.Text = record!middlename 
     cmbgenders.Text = record!gender 
     bdates.Value = record!birthdate 
     txtbplaces = record!birthplace 
     txtages = record!age 
     txtaddress.Text = record!address 
     cmbeducattainments.Text = record!educattainment 
     txtnos.Text = record!contactno 
     cstarts.Value = record!contractstart 
     cends.Value = record!contractend 

     Set record = Nothing 

    End If 
End Sub 
+0

我想你一定循環記錄搜索... – MAC

+0

是'findemployee'一個'text'或'numeric'值。如果是數字,則不應該在其周圍使用引號(''')。 –

+0

'record.MoveFirst'也可能需要。 –

回答

0
Private Sub cmdsearch_Click() 
    findemployee = inputtextbox.text 
    record.Open ("select * from employees where ID='" & findemployee & "'"), conn, 3, 3 

If record.EOF Then 
    MsgBox "NO" & findemployee & " ID WAS NOT FOUND!", vbCritical + vbOKOnly, "Error Search" 
    Set record = Nothing 
Else 
    with record 
     txtemployeeid.Text = !ID 
     txtlnames.Text = !lastname 
     txtfnames.Text = !Firstname 
     txtmnames.Text = !middlename 
     cmbgenders.Text = !gender 
     bdates.Value = !birthdate 
     txtbplaces = !birthplace 
     txtages = !age 
     txtaddress.Text = !address 
     cmbeducattainments.Text = !educattainment 
     txtnos.Text = !contactno 
     cstarts.Value = !contractstart 
     cends.Value = !contractend 

     Set record = Nothing 
    END WITH 
End If 
End Sub 
相關問題