Displayng the last child record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a parent form with a child sub form. On the parent form, I added an
AddNew button so I could calculate and display some values.
All goes well except that the child record that is displayed is the first
one while I want the last one. Is that possible? Here is some of the code
that I use:
' ***************************************************
rst.AddNew
rst.Fields("EvalNumber") = intNo + 1
rst.Fields("NO_DOSS_IR") = lngNoDossIr
rst.Update
Me.Refresh
Forms.frmMain.frmSubMain.Form.EvalDate.SetFocus

' ***************************************************
Thanks
 
Have you tried using DoCmd.GoToRecord ? If you're not familar with it,
use the Command Button Wizard to create a button and select RECORD
NAVIGATION when you get to the section where you have to indicate what
you want the button to do.
 
Hi David,
I tried what you said but cannot get it to work. I think it is possible,
though. I just need to set a little detail. Here is the problem.
My form has a sub form in it and it is on that subform that I add a new
record.
I wrote this code:
' ******************************************
Dim frm as Form
Set frm = Forms.frmMain.frmSubMain.Form
DoCmd.GoToRecord acDataForm, "frmSubMain", acNewRec
' Forms.frmMain.frmSubMain.Form.EvalDate.SetFocus
frm.EvalDate.SetFocus
' ******************************************
The DoCmd gives an error saying that the form frmSubMain is not open (which
is not true AFAIK). I tried different syntaxes but none of them works.
Here are some examples:
' ******************************************
DoCmd.GoToRecord acDataForm, "Forms.frmMain.frmSubMain", acNewRec
DoCmd.GoToRecord acDataForm, "frmMain.frmSubMain", acNewRec
DoCmd.GoToRecord acDataForm, "frmSubMain", acNewRec
DoCmd.GoToRecord acDataForm, "frm", acNewRec
DoCmd.GoToRecord acDataForm, frm, acNewRec
' ******************************************
Can someone see what is wrong?
Thanks
 
Hi Myself,
I have found out how to solve the problem and post this answer so others can
benefit from it. Thanks to Marshall Barton who patiently guided me though the
whole process. For all the details, you can check the post "AddNew button on
the Record selector" which should read "AddNew button on the Navigation bar"
(at the bottom of the form).
' **********************************
' Display the new child record (just inserted).
With Me.frmSubMain.Form.RecordsetClone
If .RecordCount > 0 Then
..MoveLast
Me.frmSubMain.Form.Bookmark = .Bookmark
End If
End With
' Set the focus on EvalDate.
Me.frmSubMain.SetFocus
Me.frmSubMain.Form.Controls("EvalDate").SetFocus
' **********************************
That's it.
Hope it helps. It sure did for me.
 
Back
Top