转到子表单上的新记录后将焦点设置在字段上

Setting focus on a field after going to a new record on a sub form

我想知道如何在通过 'acNewRec' do 命令创建记录时指示光标到达子表单中的特定字段。

目前我在我的子表单上创建了一个子例程,旨在创建一个新记录并允许用户登陆该字段 'MacroProcess':

Sub GoToNewRecord()

     DoCmd.GoToRecord , , acNewRec
     Me.MacroProcess.SetFocus

End Sub

要执行此子例程(在子窗体上),以下例程是在我的主窗体中的一个对象上构建的:

Private Sub cmdDetails_Click()

     Form_frmstaticdatadepartments07.AllowAdditions = True
     Form_frmstaticdatadepartments07.AllowEdits = True
     Form_frmstaticdatadepartments07.AllowDeletions = True
     Form_frmstaticdatadepartments07.GoToNewRecord

End Sub

在主窗体中,goToNewRecord 命令正常运行并将用户带到子窗体,但是结果并没有在新创建的记录上显示闪烁的光标。

Form_frmstaticdatadepartments07是子表单的名称吗?这是一个奇怪的解决方案,我不能相信它,因为我读过它 here,但是如果您完全摆脱 GoToNewRecord 子例程,然后更改此代码,它似乎可以工作。我不知道为什么按此顺序执行此操作(即,在转到新记录之前设置焦点)有效,但当我用我的 Access 测试它时,它确实将光标放在文本框中。

    Private Sub cmdDetails_Click()
         Form_frmstaticdatadepartments07.AllowAdditions = True
         Form_frmstaticdatadepartments07.AllowEdits = True
         Form_frmstaticdatadepartments07.AllowDeletions = True

         'First set the focus to the subform itself
         Form_frmstaticdatadepartments07.SetFocus
         'Now set the focus to the textbox on the subform
         Form_frmstaticdatadepartments07.Form.MacroProcess.SetFocus
         'Now tell the subform to go to a new record
         Form_frmstaticdatadepartments07.Form.GoToNewRecord
    End Sub