Force subform to xfer ctrl to main form

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

Guest

Access 2002: I have a main form with a subform. I would like to subform to go
back to (a new record on) the main form, after ONE record in the subform.
The record on the subform is entered after a NEW record is entered on the
mainform.

Any ideas how I might do that?

Thank you!
 
On the after insert event of the sub form write the code

Me.Parent.SetFocus
Me.Parent.[AnyFieldNameInTheMainForm].SetFocus
DoCmd.GoToRecord , , acNewRec
 
Me.Parent.txtBidder_ID.Setfocus produces error
"Can't move the focus to the control txtBidder_ID"

Ofer said:
On the after insert event of the sub form write the code

Me.Parent.SetFocus
Me.Parent.[AnyFieldNameInTheMainForm].SetFocus
DoCmd.GoToRecord , , acNewRec
--
I hope that helped
Good luck


Ron Carr said:
Access 2002: I have a main form with a subform. I would like to subform to go
back to (a new record on) the main form, after ONE record in the subform.
The record on the subform is entered after a NEW record is entered on the
mainform.

Any ideas how I might do that?

Thank you!
 
Ron Carr said:
Access 2002: I have a main form with a subform. I would like to subform to go
back to (a new record on) the main form, after ONE record in the subform.
The record on the subform is entered after a NEW record is entered on the
mainform.

Ofer's answer is great if they can't go back later to the existing record
and add a new one. If you need to ensure that they can't do that, you'll
need a bit more. Make sure the name of the subform is the name of the
subform CONTROL on the form, not the name of subform.

Sub Form_BeforeInsert (Cancel As Integer)
If Me!MySubForm.Form.RecordSetClone.RecordCount = 1 Then
Msgbox "Only 1 record is allowed"
Cancel = True
Me.Parent.SetFocus
DoCmd.GoToRecord , , acNewRec
Exit Sub
End If
End Sub

With the above code, you are forcing them to a new record on the main form,
no matter when they try to enter one in the subform.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Mybe not every field, it can't be field that set to Enabled = False,
I hope that the case, so you can set the focus to another field
--
I hope that helped
Good luck


Ron Carr said:
Me.Parent.txtBidder_ID.Setfocus produces error
"Can't move the focus to the control txtBidder_ID"

Ofer said:
On the after insert event of the sub form write the code

Me.Parent.SetFocus
Me.Parent.[AnyFieldNameInTheMainForm].SetFocus
DoCmd.GoToRecord , , acNewRec
--
I hope that helped
Good luck


Ron Carr said:
Access 2002: I have a main form with a subform. I would like to subform to go
back to (a new record on) the main form, after ONE record in the subform.
The record on the subform is entered after a NEW record is entered on the
mainform.

Any ideas how I might do that?

Thank you!
 
Good idea, but they won't use this form for addional entry, and I don't see
that this helps with the base problem...
 
Field is enabled; it is the initial data entry field.

Ofer said:
Mybe not every field, it can't be field that set to Enabled = False,
I hope that the case, so you can set the focus to another field
--
I hope that helped
Good luck


Ron Carr said:
Me.Parent.txtBidder_ID.Setfocus produces error
"Can't move the focus to the control txtBidder_ID"

Ofer said:
On the after insert event of the sub form write the code

Me.Parent.SetFocus
Me.Parent.[AnyFieldNameInTheMainForm].SetFocus
DoCmd.GoToRecord , , acNewRec
--
I hope that helped
Good luck


:

Access 2002: I have a main form with a subform. I would like to subform to go
back to (a new record on) the main form, after ONE record in the subform.
The record on the subform is entered after a NEW record is entered on the
mainform.

Any ideas how I might do that?

Thank you!
 
OK, this one is tested and it works:

Sub Form_BeforeInsert(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 1 Then
MsgBox "Only 1 record is allowed"
Cancel = True
Me.Requery
Me.Parent.txtBidder_ID.SetFocus
DoCmd.GoToRecord , , acNewRec
Exit Sub
End If
End Sub
 
Sent too soon.

This one is tested and it works:

Sub Form_BeforeInsert(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 1 Then
MsgBox "Only 1 record is allowed"
Cancel = True
Me.Requery
Me.Parent.txtBidder_ID.SetFocus
DoCmd.GoToRecord , , acNewRec
Exit Sub
End If
End Sub

If you have a problem with txtBidder_ID, it is not with the code, but with
the ability to set focus to that control. It may be that the visible
property is set to False (you can set focus in that case), or to some other
issue. Try a different control if you have a problem.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
I agree that these solutions should work (nice of me, heh...).
But I can't set focus.
Control(s - I have tried a few) are visible, enabled, not locked...darned if
I can see the problem.
I think I will start with a new form and see what happens.
 
Back
Top