|
Private Sub ComboBox1_Change()
Set CNN = CreateObject("adodb.connection")
Set rst = CreateObject("ADODB.RecordSet")
CNN.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\档案明细.accdb"
strSQL = "SELECT 列表 FROM 工作事项列表 WHERE 工作事项='" & ComboBox1.Value & "'"
rst.Open strSQL, CNN, 1, 3
arr = rst.GetRows
arr = Application.WorksheetFunction.Transpose(arr)
Me.ListBox1.Clear
Me.ListBox1.List = arr
rst.Close
CNN.Close
Set rst = Nothing
Set CNN = Nothing
End Sub
Private Sub CommandButton1_Click()
Dim tmpRst As ADODB.Recordset
Dim CNN As ADODB.Connection
Set CNN = New ADODB.Connection
CNN.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\档案明细.accdb"
Set tmpRst = New ADODB.Recordset
tmpRst.LockType = adLockPessimistic
tmpRst.CursorType = adOpenDynamic
tmpRst.Open "工作明细", CNN
CNN.BeginTrans
tmpRst.AddNew
tmpRst("姓名") = TextBox1.Text
tmpRst("单位") = TextBox2.Text
tmpRst("工作事项") = ComboBox1.Value
'多选
Dim arr, i
arr = ListBox1.List
Dim k
For i = 0 To UBound(arr)
'把选中的多列循环出来j
If ListBox1.Selected(i) Then '如果listbox1的选中状态
k = k & "、" & arr(i, 0)
End If
'写入a列表格的已有数据的下一个单元格
Next i
If Len(k) < 1 Then
MsgBox "你还没有选择!"
Exit Sub
End If
k = Mid(k, 2)
tmpRst("工作事项列表") = k
tmpRst.Update
CNN.CommitTrans
MsgBox "保存成功"
Unload Me
UserForm2.Show
End Sub
Private Sub UserForm_Initialize()
Me.ComboBox1.List = Split("调度,巡查", ",")
ListBox1.MultiSelect = 1
ListBox1.ListStyle = 1
End Sub
|
评分
-
1
查看全部评分
-
|