Results 1 to 7 of 7
  1. #1
    kennyrogersjr is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2010
    Posts
    18

    VBA/Form Navigation w/SubForm OpenForm Code

    Hi all! I'm attempting to create a multi-page navigation form. In one of the subforms, when I edit it directly and run it alone, works correctly and opens a new window with the correct form and ID number selected. My intention is to get this functionality working in the navigation form.



    NavForm: SubFormALLID, SubFormINDIVIDUALID, SubFormMISSINGDATA

    SubFormALLID: Continuous Tabular Form w/ControlButton for each Record
    Code:
    Private Sub EditPID_Click()
        DoCmd.OpenForm "SubFormINDIVIDUALID", , , "PID =" & Me!PID
    End Sub
    How can I get the subform "SubFormALLID" to send this request to the other subform "SubFormINDIVIDUALID" while using the NavForm? I've whacked at it a few times with NavigateTo and using some .Parent commands, however, none of them worked. Google hasn't been my friend.

    Please help!

    Ken

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    A navigation form is similar to sub-form only difference being that its control source changes as you click the navigation button. Further, only one nav-form is loaded at one instance. All the controls loose their values when you move from one nav-form to other. When referring the controls on any nav-form, use Forms!YourMainFormName!Nav-FormName!IndividualFormControlName - this control name is the control on the form which is visible (loaded) at that instance. If you move on to another nav-form, the above syntax will fail as the controls of nav-form loaded at that instance may have different names.

    If you need to refer to values in other nav-form, you will have to use some other control on the form or store the value in a variable before moving form that nav-form.

  3. #3
    kennyrogersjr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2010
    Posts
    18
    If I read this correctly, you mean if I have multiple NavForms? This is one Master Navigation Form. So these subForms share the same parent. Would that change your answer? I'll update my code to reflect the full path to the control, especially since Me.!PID is only for that one instance. Good call.

  4. #4
    kennyrogersjr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2010
    Posts
    18
    https://www.accessforums.net/forms/h...orm-10033.html

    This link has a somewhat functioning Access Macro, however, I'm trying to get this accomplished in VBA. I was able to get the action to stay inside the NavForm, but it doesn't relay the PID over, nor does it change the active NavForm button.

    BrowseTo:
    Object Type: Form
    Object Name: SubFormINDIVIDUALID
    Where Condition: = ="Forms![NavForm]![PID] = " & [PID]
    Data Mode: Edit

    Thoughts on if I need to pass the [PID] to a variable? I'm a little stuck.

  5. #5
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    sorry, the correct syntax for refereing to control on nav-form is Me.NavigationSubformName.Form.ControlName as is case when referring to controls on sub-form.
    While in design view, if you see the propoerties of the so called nav-form, it is mentioned as Subform/SubReport.
    To understand what I am trying to say, add text box in the parent form's header section and set its control source to =[Forms]![ParentForm]![NavigationSubform].[Form].[ControlName] ( on one of nav forms). You will see that when you navigate to other nav-form, it loses its value.
    Try this in a appropriate event -
    Code:
    Me.NavigationButtonName.NavigationWhereClause = "[PID] =" & Me!PID
    (NavigationButtonName is nav-button opening your SubFormINDIVIDUALID)
    I have not used nav-forms so I am not an expert help regarding a proper event that will always hold the required value.
    Does this works?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Are you trying to open a form or refer to controls in another form? If you want to open a form, open the Main form and do not reference the subform or controls. Applying criteria is another issue.
    DoCmd.OpenForm "NameOfFormWithNavControl"

    Then apply code similar to what is in post #5. Only thing is you can not use the Me shortcut because you need to tell the form you just opened to do things, not the original form that you are still in. You will need to replace Me with the fully qualified name and go after the properties of the Buttons in the Nav Control. (NavigationWhereClause I believe)

    This issue here is why I feel it is important to recognize that the Navigation Control is not a Form. It is a Control. The form that holds the Navigation Control does not have a recordset. It is the Navigation Control's properties that need to be addressed.

    Using the wizard to build a Nav Control from scratch, without a form, will create a new form that is not bound. Applying Where criteria to an openform method will not work.

    DoCmd.OpenForm "FormName", , , "WhereCriteria"


    Starting at post #3 may be of interest.
    https://www.accessforums.net/program...tml#post220643

  7. #7
    kennyrogersjr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2010
    Posts
    18
    Thank you both for your help, but DoCmd.BrowseTo was the correct term for use in a navigation form with subforms.

    I'll post the Where Condition tomorrow (I work night shift), but it was very short and simple to correct. I even ran into an issue where one of the nav buttons wouldn't show selected for the given subform. It turned out that when I created a backup copy of one of the subforms, I forgot to rename the association in the NavForm, which, consequently, started working when I deleted the backup and renamed my subform.

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

Similar Threads

  1. Navigation Form used as SubForm
    By jlgray0127 in forum Forms
    Replies: 2
    Last Post: 03-26-2014, 10:28 AM
  2. Replies: 18
    Last Post: 11-20-2013, 05:45 PM
  3. Replies: 2
    Last Post: 01-27-2011, 08:04 AM
  4. Replies: 2
    Last Post: 12-17-2010, 11:12 PM
  5. OpenForm in subform not working
    By eyuen in forum Forms
    Replies: 3
    Last Post: 11-10-2010, 12:03 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