reference a sub - subform control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xraive
    New Member
    • Jun 2009
    • 30

    reference a sub - subform control

    I have a Main Form (Itineraries) which has a Command Button (Command11) . On the main fom I also have a sub form (ItineraryDetai ls). Now for every Itinerary details record there is sub sub form (ItineraryAccom odation) that I want to refer to. Would you be able to help me out I have attached an image of how the form is structured.

    Below is the sample code I have tried to create.
    Code:
    Private Sub Command11_Click()
    On Error GoTo Err_Command11_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "ItineraryAccomodation"
        
        stLinkCriteria = "Me.ItineraryDetails.Form.[ItineraryDetailID]=" & Itineraries.ItineraryDetails.ItineraryAccomodation.Form.[ItineraryDetailID]
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    Exit_Command11_Click:
        Exit Sub
    
    Err_Command11_Click:
        MsgBox Err.Description
        Resume Exit_Command11_Click
        
    End Sub
    Attached Files
    Last edited by NeoPa; Jun 2 '09, 11:13 AM. Reason: Please use the [CODE] tags provided.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by xraive
    I have a Main Form (Itineraries) which has a Command Button (Command11) . On the main fom I also have a sub form (ItineraryDetai ls). Now for every Itinerary details record there is sub sub form (ItineraryAccom odation) that I want to refer to. Would you be able to help me out I have attached an image of how the form is structured.

    Below is the sample code I have tried to create.

    Private Sub Command11_Click ()
    On Error GoTo Err_Command11_C lick

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "ItineraryAccom odation"

    stLinkCriteria = "Me.ItineraryDe tails.Form.[ItineraryDetail ID]=" & Itineraries.Iti neraryDetails.I tineraryAccomod ation.Form.[ItineraryDetail ID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Command11_ Click:
    Exit Sub

    Err_Command11_C lick:
    MsgBox Err.Description
    Resume Exit_Command11_ Click

    End Sub
    I cannot make heads or tails of the Thumbnail Image, but I can show you the Syntax for referring to a Control on a Sub-Sub Form. Hopefully, this will point you in the right direction:
    Code:
    Forms![Main Form Name]![Sub-Form Name].Form![Sub-Sub Form Name].Form![Control Name]

    Comment

    • xraive
      New Member
      • Jun 2009
      • 30

      #3
      Here is what i want to do. put a button on a main form that will open up a sub form of a record that is sub form to the main form.

      I have Itinerary Form
      ItineraryDetail s
      ItinerarayAccom odations

      I would like to open the ItineraryAccomo dations form which related to the itineraryDetail s from from the Itinerary form

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32656

        #4
        This is how to refer to items on a subform - Referring to Items on a Sub-Form.

        Frankly, your question and response seem to indicate that you want us to do it for you. This is not how things work here. You're welcome to ask technical questions about how to do things, but few if any of us take kindly to requests for simple solutions.

        Comment

        • xraive
          New Member
          • Jun 2009
          • 30

          #5
          This is not what I intended but here is the code that I was working on.
          Code:
          Private Sub Command11_Click()
          On Error GoTo Err_Command11_Click
          
              Dim stDocName As String
              Dim stLinkCriteria As String
          
              stDocName = "ItineraryAccomodation"
              
              stLinkCriteria = "Me.ItineraryDetails.Form.[ItineraryDetailID]=" & Forms.[Itineraries].[ItineraryDetails].Form.[ItineraryAccomodation].Form.[ItineraryDetailID]
          
              DoCmd.OpenForm stDocName, , , stLinkCriteria
          
          Exit_Command11_Click:
              Exit Sub
          
          Err_Command11_Click:
              MsgBox Err.Description
              Resume Exit_Command11_Click
          Last edited by NeoPa; Jun 3 '09, 12:39 AM. Reason: Please use the [CODE] tags provided.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32656

            #6
            Xraive, you say you have three levels of form, and you give the names of these which is useful.

            Unfortunately you give different names in two of your posts so we don't really know what the names are.

            The important thing that's missing though is that you don't say what you want help to achieve. This is why the answers you have so far received have been quite general.

            To help you more we need accurate information of what you have, and a question that explains what you are trying to achieve.

            I'm sure with these available one or more of us will be happy to help you further.

            Comment

            • xraive
              New Member
              • Jun 2009
              • 30

              #7
              Now what I am trying to do NeoPa si:

              I have a Main Form (Itineraries)
              Sub Form (ItineraryDetai ls)
              Sub Form (ItinerarayAcco modations)


              I also have a button that is located on the Main Form.

              now when a single record is selected on the sub form (ItineraryDetai ls) i want press the buttton on the Main Form (Itineraries) and it will open up the accomodations form (ItinerarayAcco modations) for that specific record. I tried to write an event procedure to do this and it is not working.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32656

                #8
                Well, you still have a problem where the names of the items are not consistent across what you are posting. If you want help then you'd better get that sorted out first.

                I made this point in my earlier post but you seem to have ignored it or not understood it correctly. Let me see if I can help you find that problem.

                Look at the names you've posted and the code that you've tried and then say what the names actually are - as they do not match. I have no way of telling except from what you post - and that is still contradictory.

                Comment

                • xraive
                  New Member
                  • Jun 2009
                  • 30

                  #9
                  sorry about that..

                  these are the names of the forms

                  Main - Itineraries
                  Sub - ItineraryDetail s
                  Sub - ItineraryAccomo dation

                  I have a button on the main form that I would like to open the ItineraryAccomo dation form for each record in ItineraryDetail s that I select.

                  below is the code

                  Code:
                  Private Sub Command11_Click()
                  On Error GoTo Err_Command11_Click
                  
                      Dim stDocName As String
                      Dim stLinkCriteria As String
                  
                      stDocName = "ItineraryAccomodation"
                      
                      stLinkCriteria = "Me.ItineraryDetails.Form.[ItineraryDetailID]=" & Forms.[Itineraries].[ItineraryDetails].Form.[ItineraryAccomodation].Form.[ItineraryDetailID]
                  
                      DoCmd.OpenForm stDocName, , , stLinkCriteria
                  
                  Exit_Command11_Click:
                      Exit Sub
                  
                  Err_Command11_Click:
                      MsgBox Err.Description
                      Resume Exit_Command11_Click
                      
                  End Sub

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32656

                    #10
                    Right, the details look fine now :)

                    Unfortunately, at 02:53 in the morning I cannot do much just now, but I will look again tomorrow as soon as I'm able.

                    What I notice that looks strange though (you may want to look at before I can do more) is that you are using DoCmd.OpenForm on ItineraryAccomo dation. This is supposed to be a sub-sub-form (which wouldn't be opened like this). What is going on here? Is this a misunderstandin g ?

                    Comment

                    Working...