Mishanya,
The line to set focus should be Me.(DOT) not Me!(BANG)
Me.subformname.setfocus
Try that and see what happens.
What is the function of the line "Me!CRM.Form!cboSelectCRM.Requery?
This is what I setup.
I usually reserve the letters ID for my autonumber field. As in ClientID.
I
then make a field ClientNumber to store the actual client number.
Private Sub cboClientNumber_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ClientID] = " & Str(Nz(Me![cboClientNumber], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.sfrmClientDetail.SetFocus
DoCmd.GoToRecord,, acNewRecord
End Sub
Where ClientID is an autonumber field and cboClientNumber is bound to the
field ClientNumber (text)
cboClientNumber is on the parent form
Personally I would place the cboClientNumber on an unbound menu form and
call the client form from there. But that's just me.
Mike
Mishanya said:
Mike,
I did change the actual names.
The control ClientID is located in the MainForm. It already has some
code
in
AfterUpdate event:
1) to set the whole MainForm and its subforms to the selected ClientID
recordset
2) to require the unbound cboSelector in the subform that we are
talking
about to filter its underlying query to the selected ClientID.
So now the whole event looks like this:
Private Sub ClientID_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ClientID] = " & Str(Nz(Me![ClientID], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me!CRM.Form!cboSelectCRM.Requery
Me!CRM.SetFocus
DoCmd.GoToRecord , , acNewRecord
End Sub
With the code that You've advised I get error message 2105 "You can't
go
to
the specifide record" and in the Debugger I have the line
"DoCmd.GoToRecord ,
, acNewRecord" yellowed.
Can it be managed?
:
Mishanya,
Did you change the "MyFormName" and the others to your actual form and
control names.
I think it may be easier to have the code.
Me.SubformName.SetFocus
DoCmd.GoToRecord,, acNewRecord.
Replace "SubFormName" with actual name of your subform.
Where you place the code will depend on where the control ClientID is
located.
Where is the control ClientID located?
However your application is set up you still have to give the focus to
the
subform before you can tell it to go to a new record.
Regards,
Mike
Thanks for caring, Mke!
This way it resets the ParentForm to tne new entry as well. Means
the
ParentForm aplies
DoCmd.GoToRecord,,acNewRec
to itself(so all the subforms are reset also).
I want to reset the specific subform only. What do You say?
:
Mishanya,
I think you will have to set focus to the subform before you can
tell
it
to
go to a new record.
Something like this untested air code in the after update event of
the
ClientID control.
Form!MyFormName!MySubformName.Form!MySubformControlName.SetFocus
DoCmd.GoToRecord,,acNewRec
Good luck.
Mike
When I select ClientID in the ParentForm, the subform
(singleView)
is
automatically loaded with the first relevant record.
I want it to load blank, ready for a new entry. Normally I'd put
DoCmd.GoToRecord , , acNewRec
in the OnOpen event, bur it seems to work only with independent
forms,
wich
are
loaded in the new window. What in the case of subform?