Subform within tabcontrol...goto new record

BCote689

Registered User.
Local time
Yesterday, 16:43
Joined
Dec 29, 2008
Messages
13
I have a form with a tab control.

In the tab control, I have inserted a subform.

I have a command button in the subform to add a new record.

I can't seem to make it work.

For debugging purposes, I have replicated these conditions in a simple database and the command button works. This is the code I am using.


Private Sub Command6_Click()
Forms!frmTable1!frmTable2.SetFocus 'See note 1
Forms!frmTable1!frmTable2.Form!PK2.SetFocus 'focus on primary key
DoCmd.RunCommand acCmdRecordsGoToNew
End Sub
'Note 1: I can omit this line and the command button still works

I changed my code in the actual database to be equivalent and it looks like this...


Forms!frmPlay_Input!Formations.SetFocus
Forms!frmPlay_Input!SubFormations.Form!FID.SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew


and it does not work...the error trapping gives ERROR 2046...THE COMMAND OR ACTION 'RecordsGoToNew' isn't available now.

I used conditional formatting to confirm that the textbox with the primary key on the subform actually has focus.

Any advice how I can continue debugging this...
 
Are you sure this line is correct?

Code:
Forms!frmPlay_Input!SubFormations.Form!FID.SetFocu s

Note the space between the last 2 characters...

Regards,
Tim
 
Thanks for the tip...the additional space was a cut and paste problem...

However, I did find the problem...there was confusion between the tabcontrol named FORMATIONS and the subform in the tabcontrol called SUBFORMATIONS... the subform did not have focus even though the primary key field in the subform had focus as confirmed by the conditional formatting.

problem solved.

Thanks for your time.
 
You're welcome. All's well that ends well...
 

Users who are viewing this thread

Back
Top Bottom