0
votes

I would like to know how to instruct the cursor to arrive on a specific field in a sub form for when creating a record via the 'acNewRec' do command.

At present I have created a sub routine on my sub form which aims to create a new record and allow the user to land on the field 'MacroProcess':

Sub GoToNewRecord()

     DoCmd.GoToRecord , , acNewRec
     Me.MacroProcess.SetFocus

End Sub

To execute this sub routine (on the sub form) the following routine is built on an object in my main form:

Private Sub cmdDetails_Click()

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

End Sub

From the main form, the goToNewRecord command functions correctly and brings the user to the sub form however the result does not show me a flashing cursor on the newly created record.

1

1 Answers

2
votes

Is Form_frmstaticdatadepartments07 the name of the subform? It's a weird solution and I can't take credit because I read it here, but if you get rid of the GoToNewRecord subroutine altogether, then change this code, it seems to work. I don't know why doing it in this order (ie, setting the focus BEFORE going to the new record) works, but it does put the cursor in the textbox when I tested it with my 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