user2200006
user2200006

Reputation: 23

"DoCmd.GoToRecord" in Subform acts on both Form and Subform

I am using MS Access with an .accdb database. I have a form "F" which is a Split Form. The datasheet view shows client information. On that Form I have a subform "S" which is a datasheet view of data related to a client selected in the F's datasheet view. The subform has Recordset Type Dynaset.

With no code modifications, the result of selecting a client record in F is that the client record is highlighted in F and the "top/first" record is highlighted in S. My goal is to have the selected client record highlighted in F and the "addNewRec" record highlighted in S.

I have found several similar questions, but they are not quite the same, (with solutions) on this site and others. While I learned a lot from them, they all ended up with the "AdddNewRec" record of the datasheet views of both F and S being highlighted after clicking any record in F. What appeared to be the most promising solution, since it called for the record selection in S from a subroutine in the onCurrent event of F to a public subroutine resident in S which would ensure processing in S after F. I thought that would mean the subroutine in S would only impact the records in S, but it was like all the others and resulted in the "AddNewRec" records of both S and F being highlighted. My frustration factor has hit my personal high level alarm! Any help/guidance would be greatly appreciated. The code (which does sounded logical and does execute - but does not solve the problem) is:

Form - OnCurrent Event

Private Sub Form_Current()
  Forms![F]![S].Form.GoToNewRecord
End Sub

Subform

Public Sub GoToNewRecord()
  DoCmd.GoToRecord,,asNewRec
End Sub

Upvotes: 0

Views: 938

Answers (1)

Krish
Krish

Reputation: 5917

Your public function has a typo. It's not AsNewRec it's AcNewRec but that's not the real cause for your problem.

change your public sub in the S form to

Public Sub GoToNewRecord()
    Me.Recordset.AddNew 
End Sub

That should prepare the S form for a new record.

Upvotes: 0

Related Questions