Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 9th, 2006, 06:05 PM
tizmagik@gmail.com
Guest
 
Posts: n/a
Default New record in subForm on mainForm load

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
Default 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.  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles