Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 16th, 2005, 07:44 PM
Authorized User
 
Join Date: Feb 2005
Location: Frankston South, Victoria, Australia.
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating a new record in a subform

Hi. I ran into a weird difficulty the other day. I was trying to open a form from another form and move to the new record IN THE SUBFORM! I was never able to do it!

I've been programming forms for a few years with VBA but I never encountered this one! I am opening the form from a command button in another form and it is supposed to move to the new record in the subform right away but (and it makes sense) it moves to the new record in the main form. When I try to refer to the subform after the OpenForm method I am always told that the form is not open thus I cannot move to the new record.

I solved my problem by making the subform's DataEntry property to True but I loose sight of the other records in the subform.

Any ideas anyone???

Daniel

Daniel
__________________
Daniel
  #2 (permalink)  
Old February 16th, 2005, 08:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Daniel,

Private Sub Form_Load()
    Me.YourSubFormName.SetFocus
    DoCmd.RunCommand acCmdRecordsGoToNew
End Sub


HTH,

Bob

  #3 (permalink)  
Old February 17th, 2005, 10:59 PM
Authorized User
 
Join Date: Feb 2005
Location: Frankston South, Victoria, Australia.
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Humm Bob, thank you very much for the simplest answer I could dream of. I had not even think about the RunCommand method. Funny coz I do used it to save a record and other useful thing.

I really appreciate that you spent a few minutes answering this one.

Daniel

Here's the somple code that I can now use:

Private Sub Form_Load()
    If Me.OpenArgs = "NewEntry" Then
        Me.sforTesting.SetFocus
        DoCmd.RunCommand acCmdRecordsGoToNew
        DoCmd.GoToControl "FinDetailMontant"
    End If
End Sub



Daniel
  #4 (permalink)  
Old February 18th, 2005, 12:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Glad to help Daniel. Can't count the number I've times I've spent hours and lines of code on a problem, only to have someone hand me the saving two-liner.

Best,

Bob :)



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a record from a subform captainlove Access VBA 3 May 1st, 2008 11:38 AM
How do I delete a record from a subform captainlove SQL Server ASP 1 April 29th, 2008 12:01 AM
setting subform to new record skinny Access 4 January 3rd, 2006 02:57 PM
selecting only one primary record in a subform Richard Lally Access 2 April 1st, 2005 10:20 AM
Subform only may contains 1 record Stanny Access 5 December 21st, 2004 11:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.