how to highlight new record in continuous subform (1 Viewer)

eugzl

Member
Local time
Today, 18:31
Joined
Oct 26, 2021
Messages
125
Hi All.
I would like to highlight new record added to continuous subform in the parent form. For that I used code:
Code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToControl "fDeviceSubForm"
DoCmd.GoToRecord , , acLast
Forms!fInventory!fDeviceSubForm.Form.Requery
DoCmd.Close acForm, Me.Name
But in line DoCmd.GoToControl "fDeviceSubForm" I got error message
There is no field named 'fDeviceSubForm' in the current record.
Could someone show how to highlight a new record in the subform located in parent form after it was saved in child form?
Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:31
Joined
Oct 29, 2018
Messages
21,467
Hi. DoMenuItem is an old code. You must still be using a MDB. The GoToControl requires the name of a control, so double check the name of your control.
 

eugzl

Member
Local time
Today, 18:31
Joined
Oct 26, 2021
Messages
125
Hi. DoMenuItem is an old code. You must still be using a MDB. The GoToControl requires the name of a control, so double check the name of your control.
Hi theDBguy. Thanks for reply.
I substitute DoMenuItem to DoCmd.RunCommand acCmdSaveRecord and when click Save button got the same error message. The control name is correct. When I used like
Code:
DoCmd.RunCommand acCmdSaveRecord
Forms!fInventory!fDeviceSubForm.Form.Requery
DoCmd.Close acForm, Me.Name
all work fine. But I would like when record is saved and child form closed highlight new added record in the fDeviceSubForm subform.
Thanks
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 15:31
Joined
Oct 29, 2018
Messages
21,467
Hi theDBguy. Thanks for reply.
I substitute DoMenuItem to DoCmd.RunCommand acCmdSaveRecord and when click Save button got the same error message. The control name is correct. When I used like
Code:
DoCmd.RunCommand acCmdSaveRecord
Forms!fInventory!fDeviceSubForm.Form.Requery
DoCmd.Close acForm, Me.Name
all work fine. But I would like when record is saved and child form closed highlight new added record in the fDeviceSubForm subform.
Thanks
Just a thought... Have you tried the SelectRecord method? Not sure though if it will highlight the record.
 

eugzl

Member
Local time
Today, 18:31
Joined
Oct 26, 2021
Messages
125
Just a thought... Have you tried the SelectRecord method? Not sure though if it will highlight the record.
In generally is it possible to highlight new added record in continuous form? If yes. How it to do?
Thanks
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:31
Joined
Feb 19, 2013
Messages
16,607
use conditional formatting. On your form create a hidden textbox and populate it with the PK for the just saved record (should be able to capture it in the form before update event)

for conditional formatting the rule would be something like

Expression is .....[PK]=[txtPK]

apply to each control, or create another unbound textbox set it behind the other controls and apply the condition to that instead.

see this example for a multi select form, a different requirement, but the same principle applies
https://www.access-programmers.co.uk/forums/threads/multi-select-form.289116/
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:31
Joined
May 21, 2018
Messages
8,527
As @CJ_London describes, see example with code and formatting.
 

eugzl

Member
Local time
Today, 18:31
Joined
Oct 26, 2021
Messages
125
use conditional formatting. On your form create a hidden textbox and populate it with the PK for the just saved record (should be able to capture it in the form before update event)

for conditional formatting the rule would be something like

Expression is .....[PK]=[txtPK]

apply to each control, or create another unbound textbox set it behind the other controls and apply the condition to that instead.

see this example for a multi select form, a different requirement, but the same principle applies
https://www.access-programmers.co.uk/forums/threads/multi-select-form.289116/
Hi CJ_London. Thanks for reply.
In continuous form I created highlight current record. I would like highlight new added record. What I mean. When I create new record in the child form and when child form closed the control return back to the parent form where subform located in the page of Tab Control. In that moment I would like in order to a new record should be automatically selected and highlighted. How it to do?
Thanks.
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 23:31
Joined
Feb 19, 2013
Messages
16,607
in the child form close event use code to update the hidden textbox with the PK of the newly created record. You will also need to requery the form/subform whatever

You originally said you just wanted to highlight the new record - but now you also want to select it?

So in the same event set the focus to the newly created record

See the examples posted by Majp
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:31
Joined
May 7, 2009
Messages
19,230
another demo.
see the code on the "newRecordForm".
 

Attachments

  • hiliteOnSubform.accdb
    488 KB · Views: 300

eugzl

Member
Local time
Today, 18:31
Joined
Oct 26, 2021
Messages
125
another demo.
see the code on the "newRecordForm".
Hi arnelgp. Thank you for your help with demo file.
In your newRecordForm form I just insert Save button in order to have similar functionality as I have and copied and pasted your code to click button event after that I lost option to highlight and select new added record on subform. Here the code of the Save button:
Code:
Private Sub cmdSave_Click()
'check if demoForm is open
Dim iView As Integer
If SysCmd(acSysCmdGetObjectState, acForm, "demoForm") <> 0 Then
    'check if not in design view
    Dim f As Form
    Set f = Forms!demoForm
    iView = f.CurrentView
    If iView <> 0 Then
        With f!Table1.Form
            'requery the forrm
            .Requery
            'assign pkField to txtpk (on the subform)
            !txtpk = Nz(Me!pkField, -1)
            If !txtpk <> -1 Then
                'goto the record
                With .Recordset
                    .FindFirst "pkField = " & Me!pkField
                End With
            End If
        End With
    End If
    Set f = Nothing
End If

DoCmd.Close acForm, Me.Name
End Sub
What is wrong? How to fix the problem?
Thanks
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:31
Joined
May 7, 2009
Messages
19,230
hi see the code.
i keep the Unload event and add code to cmdSave button.
 

Attachments

  • hiliteOnSubform.accdb
    864 KB · Views: 296

eugzl

Member
Local time
Today, 18:31
Joined
Oct 26, 2021
Messages
125
привет посмотри код.
я сохраняю событие «Выгрузить» и добавляю код к кнопке cmdSave.
Thanks a lot. Works amazing.
Just can you explain or point me where I can read. The last statement in the Save event closes the form, but after that the logic goes to the Unload procedure instead of completing execution and passing control to the parent form. I would like to fully understand this tricky moment in the Save button code.

Thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:31
Joined
May 7, 2009
Messages
19,230
you can google the "sequence" of events on the form.
when you issue DoCmd.Close, to close the form, Unload event is called, then Close Event of the form.
 

Users who are viewing this thread

Top Bottom