Results 1 to 8 of 8
  1. #1
    FruStalin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    18

    How to chance focus from a main form to a sub form?

    Hello there

    I have this frmJournalMain on wish I have a "New" button. When OnClick the "New" button I want the subform (frmJournal) to be visible and be ready setup a new record.
    When pressing the "New" button the frmJournal shows but it is not ready for a "new record"

    This is the code:

    Private Sub cmdNy_Click()

    frmJournalMainSub1_Liste.Visible = False
    frmJournal.Visible = True

    Sagsnummer.SetFocus

    DoCmd.GoToRecord , , acNewRec

    End Sub

    How do I activate the subform to be ready to a new post? The "Sagsnummer.SetFocus" is my attempt to activate the subform - without any luck

    Regards



    Morten

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you look in VBA Help at GoToRecord, the arguments you've skipped let you specify the form that it should act on. Also, your syntax for the subform should be:

    Forms Refer to Form and Subform properties and controls
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    FruStalin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    18
    Thanks pbaldy.

    I have tried to use this statement ONClick in the main form:

    DoCmd.GoToRecord acDataForm, "frmJournal", acNewRec ("frmJournal" is my sub form)

    But it does'nt work. I recieve the error message "the object 'frmJournal' isnt open" So maybe there is something wrong with the path I put into the GoToRecord statement?!
    The document provided by the link you put up is difficult to match my need. I have tried to put in a path in the GoToRecord but I recivied a lot of different errors :-)

    Why do this have to be som damn complicated, is beone my belive!


    Still needs help.

    Regards

    Morten
    Last edited by FruStalin; 03-29-2012 at 05:54 AM.

  4. #4
    FruStalin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    18
    Hello again

    This code is the closest I have been. But I am not there yet:
    DoCmd.OpenForm "frmJournal", acNormal
    DoCmd.GoToRecord acDataForm, "frmJournal", acNewRec

    This solution opens the form in a new window, but I need it to open the form as an subform. So how do I state a path in DoCmd command???

    Feel free to show how it is done. Because I am so confused by when to use []""''(),;## etc.

    Regards

    Morten

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try either

    DoCmd.GoToRecord acDataForm, "Forms!MainformName!frmJournal", acNewRec

    DoCmd.GoToRecord acDataForm, "Forms!MainformName!frmJournal.Form", acNewRec


    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    FruStalin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    18
    Hello pbaldy

    Neither of your suggestions works. I recieve an error message saying that the form is'nt open???

    Any other suggetions. I find it strange that it is'nt possible! What is the Access problem. It got to be possible to pust af button in a main form and jump to a new post on a sub form!!!

    Regards

    Mortem

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, my bad for assuming it would work alone. This does in my test:

    DoCmd.GoToControl "frmJournal"
    DoCmd.GoToRecord , , acNewRec
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    FruStalin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    18
    Excellent work pbaldy.

    I work as inteded, thanks a lot.
    What is the differens between GoTOControl and GoToRecord?


    Many thanks again :-)

    How do I put a "Solve" to the post?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-29-2012, 09:38 AM
  2. Replies: 11
    Last Post: 01-26-2012, 01:22 PM
  3. Replies: 1
    Last Post: 12-04-2011, 09:11 PM
  4. Replies: 1
    Last Post: 11-21-2011, 07:58 AM
  5. Get Focus on Form after Modal Form closes
    By TinaCa in forum Programming
    Replies: 2
    Last Post: 09-06-2011, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums