Results 1 to 6 of 6
  1. #1
    pcotcamp is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    5

    Using GotoRecord on a subForm from a Navigation Form

    All,

    I have been struggling mightily for a couple of days now with what should be a very simple procedure. In short, I have placed a subForm (subClients) on the Navigation form of my application. The Navigation form (NavigationSubForm1) has navigation buttons to go to the first/last/next/previous record on the datasheet of the subForm. If the subForm is run standalone, the navigation buttons work just fine with: DoCmd.GoToRecord , , acNext

    I realize that the use of the Navigation form requires a different naming convention, but no matter what variation I try, it simply will not work.

    Here are the forms I am using:

    -MainMenu
    -NavigationSubForm1
    -subClients
    (derived from form ClientMain)

    Note that when I click on the navigation buttons, I can successfully give focus to the subform with: Me![subClients].SetFocus
    However, none of the following commands will move the record pointer when the navigation buttons are fired with the OnClick event:


    DoCmd.GoToRecord , , acNext
    DoCmd.GoToRecord acDataForm, "Me![subClients]", acNext
    DoCmd.GoToRecord acDataForm, Me![subClients], acNext
    DoCmd.GoToRecord acDataForm, "Forms![MainMenu]![NavigationSubForm1]![subClients]", acNext
    DoCmd.GoToRecord acDataForm, "Forms![MainMenu]![NavigationSubForm1]![subClients]", acNext
    DoCmd.GoToRecord acDataForm, Forms![MainMenu]![NavigationSubForm1]![subClients], acNext
    DoCmd.GoToRecord acDataForm, "Forms![MainMenu]![NavigationSubForm1]![ClientMain]", acNext 'ClientMain is the form from which subClient is derived.

    I have also tried putting DoCmd.GoToRecord , , acNext in the code of the subForm, making it Public and calling the procedure from the navigation buttons of the parent form. No joy.

    Can someone shed some light on the proper syntax or procedure for me? I am pulling my hair out over this simple task.

    What am I missing?

    Thank you,

    -Paige

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    What exactly happens when you click on the Next Record Command button? Any errors? Are those by chance enabled?

  3. #3
    pcotcamp is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    5
    Quote Originally Posted by burrina View Post
    What exactly happens when you click on the Next Record Command button? Any errors? Are those by chance enabled?
    When I click on the Next Record Command button, focus moves to the first column, of the first row of the subform, as it should. With the simplest form of the code that I have tried (see below), it then results in the following error: "Run-time error 2498. An expression you entered is the wrong data type for one of the arguments".

    [code

    Private Sub GoNext_Click()


    'Set Focus to subForm and then move the record pointer.
    Me![subClients].SetFocus 'Works correctly! Gives focus to subForm.


    DoCmd.GoToRecord , , acNext 'Fails with "Run-time error 2498: An expression you entered is the wrong data type for one of the arguments".
    'DoCmd.GoToRecord acDataForm , "Me![subClients]" , acNext 'Fails with "Run-time error 2498: The object 'Me![subClients]' isn't open.


    End Sub


    /code]

    As noted previously, no manner of variations on the DoCmd.GotoRecord method seem to work.

    Suggestions?

    -Paige

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Are those Record Command buttons actually on the subform itself? If your getting that error, it has to do with your data structure, not the go to record code.
    You should NOT have to set focus on the subform if the command buttons are on the form itself.

    HTH

  5. #5
    pcotcamp is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    5

    Using GotoRecord on a subForm from a Navigation Form

    Quote Originally Posted by burrina View Post
    Are those Record Command buttons actually on the subform itself? If your getting that error, it has to do with your data structure, not the go to record code.
    You should NOT have to set focus on the subform if the command buttons are on the form itself.

    HTH
    No, the control buttons are currently on the NavigationSubForm1 page, not the subform. The reason I have done so, is that I would like to display the subform (subClients) as as datasheet that the user can scroll through or search on. As you know, when you display a subform as a data sheet, it does not show any other controls on the page. My goal is to have a set of navigation controls for the subform, as well as an "Add", "Edit", Delete" and "Print" button, all located on NavigationSubForm1. Is there a better solution?

    The difficulty, I suspect, is that I do not have any other data elements on the Navigation form with which to bind to the subform. When I attempted to do so, I only get one record at a time displaying in the subform. Likewise, attempting to make the "Clients" tab on the Navigation Form a split form won't work, as that only displays the top half.

    What am I missing conceptually here? All I am trying to do is move the record pointer on the subform with a navigation button on the the parent form. I realize that the problem is likely the lack of binding, but I can't figure it out. Binding any fields on the parent results in a single record display on the subform and I wind up chasing my tail. Very frustrating.

    Thanks,

    -Paige

  6. #6
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    It has always been my experience that the simplest solution is generally the best. I'm not saying what you want to do can't be done but I would opt for a Continuous form which can be made to look just like a datasheet and would eliminate your issue.

    Should you choose you accept this mission, as usual we disavow all knowledge and you are on your own. This code will self destruct in 5 seconds!

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

Similar Threads

  1. VBA/Form Navigation w/SubForm OpenForm Code
    By kennyrogersjr in forum Forms
    Replies: 6
    Last Post: 05-01-2014, 09:59 AM
  2. Navigation Form used as SubForm
    By jlgray0127 in forum Forms
    Replies: 2
    Last Post: 03-26-2014, 10:28 AM
  3. Replies: 4
    Last Post: 10-08-2012, 05:33 PM
  4. Subform Reference on Navigation Form
    By rts in forum Forms
    Replies: 1
    Last Post: 06-05-2012, 02:05 PM
  5. Replies: 0
    Last Post: 03-15-2009, 03:22 AM

Tags for this Thread

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