0

我想在表单中创建一个列表框,带有多个选择和复选框。未找到 liststyle 属性并且网页的说明不起作用: https ://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/liststyle-property https: //docs.microsoft.com/en-us/office/vba/api/outlook.listbox

4

1 回答 1

0

目前尚不清楚您正在尝试做什么,但将复选框和列表框格式化为看起来像同一个控件。然后在幕后将它们与 vba 联系起来。我发现了一些非常旧的代码,其中有一个非标准的数据输入表单和一堆复选框。当时我添加了一个按钮并将所有内容都连接到按钮单击事件中。

在此处输入图像描述

Private Sub cmdSaveLog_Click()
SaveLogEntry cmbHour1, cmbMinutes1, txtNotes1, chkAsleep1, chkSaveEntry1
SaveLogEntry cmbHour2, cmbMinutes2, txtNotes2, chkAsleep2, chkSaveEntry2
SaveLogEntry cmbHour3, cmbMinutes3, txtNotes3, chkAsleep3, chkSaveEntry3
SaveLogEntry cmbHour4, cmbMinutes4, txtNotes4, chkAsleep4, chkSaveEntry4
SaveLogEntry cmbHour5, cmbMinutes5, txtNotes5, chkAsleep5, chkSaveEntry5
SaveLogEntry cmbHour6, cmbMinutes6, txtNotes6, chkAsleep6, chkSaveEntry6
SaveLogEntry cmbHour7, cmbMinutes7, txtNotes7, chkAsleep7, chkSaveEntry7
SaveLogEntry cmbHour8, cmbMinutes8, txtNotes8, chkAsleep8, chkSaveEntry8
SaveLogEntry cmbHour9, cmbMinutes9, txtNotes9, chkAsleep9, chkSaveEntry9
SetFilter
End Sub
Private Sub SaveLogEntry(cmbHours As ComboBox, cmbMinutes As ComboBox, txtNotes As textbox, chkAsleep As CheckBox, chksave As CheckBox)
'note logtime is inserted as a double, txtdetails needs to be quoted in string
'If Trim(cmbHours.value & vbNullString) = vbNullString Then 'textbox empty
If chksave.value = True Then
Dim DailyID As Long
Dim item As Variant
Dim logtime As Double 'insert and dates don't mix
'Dim currentboy As Long
'logtime = CDbl(CDate(cmbDate.value)) + (txtHour.value + txtMinute.value / 60) / 24 'how to convert date, hour, minute to date with time
'logtime = Int(cmbDate.value) + cmbHours.value + cmbMinutes.value
' loop list box
'DailyID = GetDailyID(CLng(lstBoys.Column(0, item)), CDate(cmbDate.value))
DoCmd.SetWarnings False
For Each item In lstBoys.ItemsSelected
DailyID = GetDailyID(CLng(lstBoys.ItemData(item)), CDate(cmbDate.value)) 'group by date at start of shift
If cmbHours.value + cmbMinutes.value > 0.5 Then 'before midnight
'DailyID = GetDailyID(CLng(lstBoys.ItemData(item)), CDate(Int(cmbDate.value)))
'DailyID = GetDailyID(CLng(lstBoys.ItemData(item)), CDate(cmbDate.value))
logtime = CDate(cmbDate.value) + cmbHours.value + cmbMinutes.value
Else
'DailyID = GetDailyID(CLng(lstBoys.ItemData(item)), CDate(Int(DateAdd("d", 1, cmbDate.value))))
'DailyID = GetDailyID(CLng(lstBoys.Column(0, item)), CDate(Int(DateAdd("d", 1, cmbDate.value))))
logtime = DateAdd("d", 1, cmbDate.value) + cmbHours.value + cmbMinutes.value
End If
'DailyID = GetDailyID(CLng(lstBoys.ItemData(item)), CDate(Int(cmbDate.value))) ' for some reason date had a time stamp so int to truncate time
 'DailyID = GetCorrectDailyID(CLng(lstBoys.ItemData(item)), CDate(Int(cmbDate.value)), cmbHours.value + cmbMinutes.value) ' for some reason date had a time stamp so int to truncate time
 If IsNull(txtNotes) Or txtNotes = "" Then
DoCmd.RunSQL ("INSERT INTO NightLogs ( DailyID, InspectionTime, Asleep, StaffID) " & _
"SELECT " & DailyID & ", " & logtime & ", " & chkAsleep.value & ", " & cmbStaff.value)
 Else
DoCmd.RunSQL ("INSERT INTO NightLogs ( DailyID, InspectionTime, Asleep, Details, StaffID ) " & _
"SELECT " & DailyID & ", " & logtime & ", " & chkAsleep.value & ", """ & txtNotes & """" & ", " & cmbStaff.value)
End If
Next item
DoCmd.SetWarnings True
Else
'do nothing
End If
End Sub

根据您想要做什么,您也可以使用复选框单击事件而不是按钮。关键是让 Access 控件做他们擅长的视觉工作,并使用 VBA 来引用设置等控件并完成工作。

于 2021-08-24T05:27:44.903 回答