By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

New record in subForm on mainForm load

P: n/a
I have a Starting form ("frmStart") and a main form ("frmCustomer")
inside frmCustomer are two subform, one with it's own subform. So
frmCustomer has two subforms ("sbfArtist" and "sbfAddress") inside
subform "sbfArtist" is another subform, "sbfTitle"... I'll try to
create a visible heiarchy:


I hope that helps set up the picture...

Anyway, inside frmStart is a command button that allows the user to
enter a new Address in frmCustomer. The CustomerID is readily available
form frmStart. I don't want to do this with SQL code as I need the
ability to allow the user to back out of creating a new entry and to
edit the fields before it's updated. Inside frmCustomer_Load() I tried
using RunCommand acCmdRecordsGoToNew after setting the focus to the
subform but that did not work.

I load and display the correct CustomerID with:

Private Sub Form_Load() ' frmCustomer
If Me.OpenArgs = "NewBillAddress" Then
With Me.RecordsetClone
.FindFirst "[CustomerID]=" & Forms!frmStart!Customer
If Not .NoMatch Then
Me.Bookmark = .Bookmark
With Me.[sbfAddress].Form
End With
End If
End With
End If
End Sub

That executes without error but fails to set focus to a New record in

After getting this to work I will attempt to create similar
functionality to the 2-level-subform (frmCustomer>>sbfArtist>>sbfTitle)
and I'm sure I can figure that out if I can just get this to work.

Any help would be greatly appreciated. Thanks!

Aug 9 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
I have figured it out, this is how I did it:

In the button on frmStart to open the frmCustomer and enter a new
address is this code:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmCustomer", , , _
  2. "CustomerID=" & Me!Customer, acFormEdit, acDialog, "NewAddress"
  3. Me![BillAddress].Requery
on the Form_Load event of frmCustomer is the following:
Expand|Select|Wrap|Line Numbers
  1. '  ... select statement handling the OpenArgs ...
  2. Me.sbfAddress.SetFocus
  3. DoCmd.GoToRecord , , acNewRec
  4. '  ... end select
That works like a charm. Now, for doing the same to sbfTitle, which is
a subform of sbfArtist ... the key is to set focus to the 'parent'
subform and then set the focus to the 'child' subform and go to
a new record, here is the code for those interested (this goes in the
Form_Load event):

Expand|Select|Wrap|Line Numbers
  1. ' ... select statement ...
  2. Me.sbfArtist.SetFocus
  3. Me!sbfArtist.Form!sbfTitle.SetFocus
  4. DoCmd.GoToRecord , , acNewRec
  5. ' ... end select
Aug 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.