SetFocus 到子窗体数据表视图中的控件,其中复选框 = True
SetFocus to a control in a subform datasheet view where checkbox = True
I 窗体包含一个将多条记录列为数据表的子窗体。在子表单中有一个名为 "Select" 的复选框类型列。 (控件名称为 chk_select)。
此列用于select他们想在单独的表格中打开哪些记录。通过选中复选框来检查他们想要打开的记录后,一个按钮将打开一个单独的详细信息表单,显示 "Select" 列 = True 的记录。
我的问题是,除非焦点位于数据表中复选框已 selected 的行上,否则 Access 无法打开详细信息表单。
例如,我会选中 select 我想打开的记录的复选框,然后单击未选中该复选框的另一行 selected,然后尝试打开详细信息窗体,但 Access 似乎没有看到有记录 selected。但是,如果我将光标移动到复选框被选中的任何行,那么详细信息表单就可以很好地打开复选框被 selected 的所有记录。
我目前的解决方法是显示一个消息框,尝试让用户将光标移动到 select 复选框所在的行。但我希望在打开其他表单之前自动完成此操作,以避免对用户造成任何混淆。
所以我需要一种方法,在打开详细信息表单之前,将 SetFocus 用于子表单控件,其中复选框 = True。
有什么方法可以做到这一点或解决方法吗?
这是我目前所拥有的。
谢谢。
Private Sub btn_open_estimate2_Click()
If Forms![View Estimates]![TblEstimates subform]![chk_select] = True Then
'Forms![View Estimates]![TblEstimates subform]![chk_select].SetFocus ***Need something similar to Where [chk_select]=True
DoCmd.OpenForm "Edit Estimate", , , "TblEstimates.select = True"
DoCmd.Close acForm, "View Estimates", acSaveYes
Else
MsgBox "Please select an Estimate to open, or " & _
"move the cursor to a selected Estimate to be able to open it", VbMsgBoxStyle.vbExclamation, "No Estimate Selected"
End If
End Sub
作为验证复选框的另一种方法。这可能会解决您的问题。
If Forms![View Estimates]![TblEstimates subform]![chk_select] = True Then
至
If Not IsNull(DLookup("[Edit Estimates]", "[TblEstimates]", "[Select] = True")) Then
使用RecordsetClone:
Private Sub btn_open_estimate2_Click()
Dim rs As DAO.Recordset
Set rs = Me![TblEstimates subform].Form.RecordsetClone
rs. FindFirst "[select] = True"
If rs.NoMatch Then
MsgBox "Please select an Estimate to open.", VbMsgBoxStyle.vbExclamation, "No Estimate Selected"
Else
DoCmd.OpenForm "Edit Estimate", , , "TblEstimates.select = True"
DoCmd.Close acForm, Me.Name, acSaveYes
End If
rs.Close
End Sub
I 窗体包含一个将多条记录列为数据表的子窗体。在子表单中有一个名为 "Select" 的复选框类型列。 (控件名称为 chk_select)。
此列用于select他们想在单独的表格中打开哪些记录。通过选中复选框来检查他们想要打开的记录后,一个按钮将打开一个单独的详细信息表单,显示 "Select" 列 = True 的记录。
我的问题是,除非焦点位于数据表中复选框已 selected 的行上,否则 Access 无法打开详细信息表单。
例如,我会选中 select 我想打开的记录的复选框,然后单击未选中该复选框的另一行 selected,然后尝试打开详细信息窗体,但 Access 似乎没有看到有记录 selected。但是,如果我将光标移动到复选框被选中的任何行,那么详细信息表单就可以很好地打开复选框被 selected 的所有记录。
我目前的解决方法是显示一个消息框,尝试让用户将光标移动到 select 复选框所在的行。但我希望在打开其他表单之前自动完成此操作,以避免对用户造成任何混淆。
所以我需要一种方法,在打开详细信息表单之前,将 SetFocus 用于子表单控件,其中复选框 = True。
有什么方法可以做到这一点或解决方法吗?
这是我目前所拥有的。
谢谢。
Private Sub btn_open_estimate2_Click()
If Forms![View Estimates]![TblEstimates subform]![chk_select] = True Then
'Forms![View Estimates]![TblEstimates subform]![chk_select].SetFocus ***Need something similar to Where [chk_select]=True
DoCmd.OpenForm "Edit Estimate", , , "TblEstimates.select = True"
DoCmd.Close acForm, "View Estimates", acSaveYes
Else
MsgBox "Please select an Estimate to open, or " & _
"move the cursor to a selected Estimate to be able to open it", VbMsgBoxStyle.vbExclamation, "No Estimate Selected"
End If
End Sub
作为验证复选框的另一种方法。这可能会解决您的问题。
If Forms![View Estimates]![TblEstimates subform]![chk_select] = True Then
至
If Not IsNull(DLookup("[Edit Estimates]", "[TblEstimates]", "[Select] = True")) Then
使用RecordsetClone:
Private Sub btn_open_estimate2_Click()
Dim rs As DAO.Recordset
Set rs = Me![TblEstimates subform].Form.RecordsetClone
rs. FindFirst "[select] = True"
If rs.NoMatch Then
MsgBox "Please select an Estimate to open.", VbMsgBoxStyle.vbExclamation, "No Estimate Selected"
Else
DoCmd.OpenForm "Edit Estimate", , , "TblEstimates.select = True"
DoCmd.Close acForm, Me.Name, acSaveYes
End If
rs.Close
End Sub