帶部門id部門名稱的修改窗體的製作
Private Sub Form_Load()
Dim rs As Recordset
Set rs = QueryExt("SELECT DepID,DepName FROM Depart") '獲取部門資料
With cmbDepart
.Clear '清空組合框
Do While Not rs.EOF '迴圈新增部門
.AddItem rs(1) '新增部門名稱
.ItemData(.NewIndex) = rs(0) '儲存部門編號
rs.MoveNext '處理下一記錄
Loop
End With
rs.Close
cmdOK.Visible = True '顯示“確定”按鈕
CmdEXIT.Caption = "取消" '設定“退出”按鈕的標題
Select Case iMode '根據傳入的模式引數選擇
Case 0 '新增員工
cmdOK.Caption = "確定" '修改按鈕標題
Me.Caption = "新增職員" '修改窗體標題
Case 1 '修改員工資訊
cmdOK.Caption = "儲存" '修改按鈕標題
Me.Caption = "修改職員資訊" '修改窗體標題
Set rs = QueryExt("SELECT * FROM Emp WHERE EmpID=" & GetID(gID))
With rs
txtName.Text = .Fields("EmpName") '姓名
cmbSex.ListIndex = IIf(.Fields("EmpSex") = 0, 0, 1) '性別
txtMobile.Text = .Fields("EmpTele") '手機
txtZW.Text = .Fields("EmpDuty") '宅電
End With
For i = 0 To cmbDepart.ListCount - 1
If cmbDepart.ItemData(i) = rs("EmpDepart") Then
cmbDepart.ListIndex = i '客戶型別Id
Exit For
End If
Next
End Select
OK = False
End Sub
這個窗體的製作
左邊是treeview,右邊是listview
Private Sub tvDep_NodeClick(ByVal Node As MSComctlLib.Node) '單擊樹型控制元件節點
Dim deID As String, rs As ADODB.Recordset, strSQL As String
deID = GetID(Me.tvDep.SelectedItem.Key)
If deID = 0 Then '根
strSQL = "SELECT EmpID,EmpName,EmpDuty,EmpSex,EmpDepart," & _
"EmpTele,EmpInDate FROM Emp" '獲取所有員工資料
Else '部門
strSQL = "SELECT EmpID,EmpName,EmpDuty,EmpSex,EmpDepart," & _
"EmpTele,EmpInDate FROM Emp WHERE EmpDepart=" & deID '獲取指定部門的員工資料
End If
Set rs = QueryExt(strSQL)
lvEmp.ListItems.Clear '清除當前的列表內容
Do While Not rs.EOF '迴圈顯示記錄集中的資料
AddToLV rs.DataSource, lvEmp, False '新增一項資料
rs.MoveNext '處理下一記錄
Loop
End Sub