forms - 用于调用子表单的 SelHeight 属性 Value 的 VBA 代码不起作用 - 语法错误?

我的目标:我在表单中有一个子表单,我想在子表单中的用户选择记录中获取一个字段的 value,并使用该 value 在我的表单中填充一个字段。我正在使用 .Selheight 来确定子表单中选择的记录数。代码是这样的:

If Me.Frm_ICD10CMCodes.Form.SelHeight = 0 Then
        MsgBox "Please select one record. You have selected " & Me.Frm_ICD10CMCodes.Form.SelHeight & " records.", vbOKOnly, "Dr Talking:"
    ElseIf Me.Frm_ICD10CMCodes.Form.SelHeight = 1 Then
        'Copy the diagnosis in the diagnosis box
    ElseIf Me.Frm_ICD10CMCodes.Form.SelHeight > 1 Then
        MsgBox "Please select only one record.", vbOKOnly, "Dr Talking:"
    End If

现在的问题是,无论我在运行代码时选择了多少条记录,Form.SelHeight 属性都会不断返回 Value 0。

我一定做错了什么。 ,但我没有收到错误。

回答1

离开子表单后,所选记录将被取消选择。

这适用于我的主表单来显示所选记录的计数:

Option Compare Database
Option Explicit


Private Sub Form_Current()

    Me!txtSelected.Value = Me.SelHeight
    
End Sub


Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    
    Me!txtSelected.Value = Me.SelHeight

End Sub


Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Me.NewRecord = True Then
        Me!txtSelected.Value = 0
    Else
        Me!txtSelected.Value = Me.SelHeight
    End If
    
End Sub


Private Sub Form_Open(Cancel As Integer)

    Me.KeyPreview = True

End Sub

相似文章

随机推荐

最新文章