How to move a subform to a new record ?

lvr

New member
Local time
Today, 04:45
Joined
Aug 22, 2008
Messages
9
Hello,

I would like from my main form to move a subform to a new record.
Usually I'm doing that like this:
Code:
DoCmd.GoToRecord acDataForm, me.name,acNewRec
But here with the subform, I've tried to write:
Code:
DoCmd.GoToRecord acDataForm, "MySubForm" ,acNewRec
but I'm said that MySubForm is not opened and indeed it is not open per se but as a subform !!!!

Any idea on how to achieve this ?

Thanks,

Laurent
 
You need to setfocus to the subform before moving it to a new record.

Me.sfSubFormame.Setfocus

Regards
 
Thanks. And then ? How do I write that the DoCmd.GotoRecord must occur on the subform ?
 
Then follow by:

DoCmd.RunCommand acCmdRecordsGoToNew

Regards
 
You also had a comma missing in your example:

DoCmd.GoToRecord acDataForm, "mySubForm", , acNewRec

Regards
 
Hi thanks for ideas !
None of these works.
- DoCmd.RunCommand gives me "The command or action RecordsGoToNew ins't available now"
- DoCmd.GoToRecord gives me "The object 'frmDistances' isn't open."

I will give a precision: what i'm doing is to try to move the subform B to a new record from a subform A.

Here is the code (and the different attemps in comments) from the subform A:
Code:
Private Sub Form_Current()
    Dim frm As Form
    On Error GoTo InvalidMoment
    ' Retrieving form behind second subform 
    Set frm = Forms("frmManageDistancesManquantes").frmDistances.Form
    ' Setting focus to second subform
    Forms("frmManageDistancesManquantes").frmDistances.SetFocus
    
    On Error GoTo 0
    ' Trying to move second subform's form to new record
    'DoCmd.GoToRecord acDataForm, Forms("frmManageDistancesManquantes").frmDistances.Name, acNewRec
    'DoCmd.GoToRecord acDataForm, Forms("frmManageDistancesManquantes").frmDistances.Name, , acNewRec
    DoCmd.RunCommand acCmdRecordsGoToNew
    
    ' Setting second subform's form default values
    frm.lstPointDe.DefaultValue = Me!idPointDe
    frm.lstPointA.DefaultValue = Me!idPointA
    frm.txtItineraire.DefaultValue = """" + Me.txtItinéraire + """"
    frm.Distance.DefaultValue = IIf(IsNull(Me!Distance), 0, Me!Distance)
    frm.Durée.DefaultValue = IIf(IsNull(Me!Durée), 0, Me!Durée)
    
InvalidMoment:

End Sub
 
I created a mainform (Form1) with two subforms (sf1Table1 & sf2Table1). On the first subform I placed a command button and put the following into the OnClick event:

Private Sub Command13_Click()
Forms!Form1.Form!sf2Table1.SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew
End Sub

With sf1Table1 having the focus a click on the command button moved the focus to the New record row in sf2Table1.

I'm guessing that the AllowEdits and/or AllowAdditions properties are set to True as in my example.

regards
 
Hello Terry,
Thanks for the effort, but it just doesn't work. I keep having this message that the command is not available "now".
I was in DataEntry mode, I moved it to false, to no avail. I keep staying on the last record. I will do the "gotonewrecord" manually :(
 
And have you confirmed, as asked, that the new record is available in your form?
That the subform does receive the focus.
And that the method is called without any subsequent parameters.

That said - I'd just go with
Code:
Forms("frmManageDistancesManquantes").frmDistances.Form.Recordset.AddNew

Assuming you're in Acc2000 or newer and that you do have that new record available on your form.
Saves messing about, and relying upon, focus.
 
Ok guys. Thanks. I tried you last proposition and I think it works (because i'm getting a new record, but not all the times I expected). I guess I have some trouble with events. I will check the rest by myself.
Any to way to mark this topic as "resolved" ?
 

Users who are viewing this thread

Back
Top Bottom