PDA

View Full Version : Access VBA Retain focus on record



fuzzyfernie
08-21-2019, 01:06 PM
I have several forms that the Default View is set to Split Form. When a record is selected in the split form it fills changes the field filled in the main form. I need to be able to stay on the same person as I move through the several forms. Is there a way to keep the record selected in the first form in all the other forms? I am trying to keep the current record Id and pass it on to the other forms but not able to get the record selected. I have a total of 8 forms which are all opened at the same time with a button.:think:

Private Sub Form_Current()
Me!Text1 = CurrentFormRecord(Me) //I am using this to see if the correct record is being kept

Tempid = Me!Text1

Forms![Form2].Form.Tag = Tempid //I am attempting to assign the selected record on this first form to the second form


Function CurrentFormRecord(frm As Form) As Long
CurrentFormRecord = frm.CurrentRecord
End Function

OBP
08-23-2019, 04:17 AM
I have to ask the question of why it takes 8 forms to enter your data?

As to your problem, there are a couple of things I can suggest, one is a Mainform or Tabbed Mainform where the Primary Record controls all those on the Tabs or subforms via Master/Child links which is the correct way to control records.
Second providing the Forms are using the same recordset in the same order you can also use the Form's Bookmarks like this (which mimicks a split form).

If Me.ID <> Me.tblCustomer!ID Then

Me.tblCustomer.Form.Bookmark = Me.Bookmark

End If

and for subform

If Me.ID <> Me.Parent.ID Then

Me.Parent.Bookmark = Me.Bookmark

End If




You can also use VBA to control which record a form opens on when you open them, but it does filter the form.

ps you should also set the form "Cycle" property to "Current Record" which prevents tabbing or Return key presses taking you to the next record.