所以我使用了建议的编码,但无法正常工作。因此,我对其进行了编辑和澄清,希望我的文档可能确实很挑剔,但这也不起作用。我在该部分的完整代码如下。谁能帮我了解为什么这不起作用?
下面的几行首先将文本框字段移动到我的数据库,然后我的数据库进行一些计算。这些计算将返回“ T”或“ F”。然后,我的用户表单将检索该信息,并且如果字段为“ T”,则会在用户表单中实时选中复选框。我试图使我的编码禁用一个没有“ T”且未被选中的复选框,因此无法在用户窗体中进行标记。但是,我确实需要用户能够从其后有“ T”并被选中的复选框中删除选中标记。
我拥有的代码在下面,并且它不会禁用未选中的复选框,并且它们后面没有“ T”。
'When time is entered, time transfers immediately to spreadsheet datafield and sends back to userform which meals are allowed.
Dim TargetRow As Integer
TargetRow = Sheets("Codes").Range("D43").Value + 1
With Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 26)
.Value = TimeValue(txtArrivalTime)
.NumberFormat = "hh:mm" 'arrival time
End With
'''MEALS ALLOWED PER SPREADSHEET TO USERFORM'''
If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 28).Value = "T" Then
frmUserTravel.chkMorning = Checked
End If
'If frmUserTravel.chkMorning = Unchecked Then
' frmUserTravel.chkMorning.Enabled = False
'End If
If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 30).Value = "T" Then
frmUserTravel.chkMidday = Checked
End If
'If frmUserTravel.chkMidday = Unchecked Then
' frmUserTravel.chkMidday.Enabled = False
'End If
If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 32).Value = "T" Then
frmUserTravel.chkEvening = Checked
End If
'If frmUserTravel.chkEvening = Unchecked Then
' frmUserTravel.chkMidday.Enabled = False
'End If
'''END MOVEMENT OF MEALS ALLOWED TO USERFORM'''
End Sub```
禁用用户不符合使用条件的复选框:
If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 28).Value = "T" Then
frmUserTravel.chkMorning = Checked
Else
frmUserTravel.chkMorning = Unchecked
frmUserTravel.chkMorning.Enabled = False
End If
If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 30).Value = "T" Then
frmUserTravel.chkMidday = Checked
Else
frmUserTravel.chkMidday = Unchecked
frmUserTravel.chkMidday.Enabled = False
End If
If Sheets("Travel Expense Voucher").Range("Data_Start").Offset(TargetRow, 32).Value = "T" Then
frmUserTravel.chkEvening = Checked
Else
frmUserTravel.chkEvening = Unchecked
frmUserTravel.chkEvening.Enabled = False
End If