Connecting Tech Pros Worldwide Help | Site Map

New record in subForm on mainForm load

  #1  
Old August 9th, 2006, 06:05 PM
tizmagik@gmail.com
Guest
 
Posts: 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:

frmStart
----frmCustomer
--------sbfAddress
--------sbfArtist
------------sbfTitle

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
Me.sbfAddress.Form.SetFocus
Me.sbfAddress.Form.addNewRecord
End With
End If
End With
End If
End Sub

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

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!

  #2  
Old August 11th, 2006, 04:25 PM
tizmagik@gmail.com
Guest
 
Posts: n/a

re: New record in subForm on mainForm load


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
  4.  
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
  5.  
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
  6.  
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
TAB CONTROL to load a FORM ApexData@gmail.com answers 3 December 11th, 2006 02:35 PM