Results 1 to 6 of 6
  1. #1
    Axeia is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2011
    Posts
    16

    Use value of selected row on subform for the query of another subform.

    Hello,

    Could anyone please tell me how I can link two subforms together on a form?
    On the attached screenshot there is a form with two subforms. The left one is displaying de "Zaal" table and the right one is displaying de stoel table.

    What I want to archieve and it's not doing at the moment is:


    When "Grote Zaal" is selected on the left it should show all the results on the right.

    I was hoping to do this by setting the record source of the right subform by changing the criteria of the form (of de Zaal column) on the right to something like "[Forms].[dbo_Zaal_subform].[Zaalnaam]" but this gets me an input dialog.

    Is this even possible this way or I should be doing this using VBA and if so where can I find an example?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    What exactly do you mean by all records on the right. Can you describe the data a little more and tell us how the subforms are/should be related? I see 51 records on the right -- how many should there be?

  3. #3
    Axeia is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2011
    Posts
    16
    On the left there is the column 'Zaalnaam' which should match with the 'Zaal' column in the subform on the right.

    Basically on the right it should just be a
    WHERE Zaal = 'leftsubform.selectedrow.Zaalnaam'

    Attached a screenshot with the relative part of the original DB diagram.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    When "Grote Zaal" is selected on the left it should show all the results on the right.
    As mentioned, I see 51 records in the right subform. How many did you expect?

    Can you show the Recordsource for the current right subform?

    I think the recordsource for the right subform would be (untested, but best guess)

    Me!dbo_stoel_subform.Form.RecordSource = "Select * from dbo_stoel where stoel.zaal = " & Forms!dbo_zaal_subform.Form.Zaalnaam
    Last edited by orange; 05-07-2011 at 04:16 PM. Reason: change zaalname to zaalnaam

  5. #5
    Axeia is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2011
    Posts
    16
    Thank you Orange, getting close!
    The query is now
    Code:
    SELECT dbo_Stoel.Stoelnummer, dbo_Stoel.Zaal, dbo_Stoel.Rang
    FROM dbo_Stoel
    WHERE (((dbo_Stoel.Zaal)=[Forms]![dbo_Zaal subform].[Form].[CurrentRecord]));
    But it seems CurrentRecord doesn't give back the text of the selected column as the query is still prompting me for input rather than using the value.
    I also tried the column name (Zaalnaam) which does the same (still prompting for input). When I manually enter "Grote Zaal" in the popup that prompts for input it works as expected.
    .[CurrentRecord] doesn't seem to have any properties as the smartmenu/intellisense (whatever it's called in access) doesn't come up with anything.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    I'm not following the CurrentRecord thing.
    Don't you want the recordsource for the
    stoel subform to only have records for
    Grote Zaal?

    You may have to say Forms!dbo_zaal_subform.Form.Zaalnaam.Value ????
    You may have to issue a requery, once you have modified the recordsource.

    I'm working with Acc2003.

    After posting this, I went searching for a sample Form with 2 subforms. If you have the Northwind database from M$oft,
    the Customer Orders Form has 2 subforms - Customer Orders Subform1 and Customer Orders Subform2. These are "syncing records". I am going to attach 2 screenshots showing which Order is selected (top subform1) and which Product(s) belong to that Order (lower subform2).

    Here is the OnCurrent code behind Subform1

    Code:
    Sub Form_Current()
    ' This code created by Form Wizard.
    'This code is in Subform1
        Dim strParentDocName As String
    
        On Error Resume Next
        strParentDocName = Me.Parent.name
    
        If Err <> 0 Then
            GoTo Form_Current_Exit
        Else
            On Error GoTo Form_Current_Err
            Me.Parent![Customer Orders Subform2].Requery
        End If
    
    Form_Current_Exit:
        Exit Sub
    
    Form_Current_Err:
        MsgBox Err.Description
        Resume Form_Current_Exit
    
    End Sub

    Good luck

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

Similar Threads

  1. Pass Subform filter to subform in report
    By camftm in forum Programming
    Replies: 16
    Last Post: 07-19-2011, 07:12 AM
  2. Replies: 3
    Last Post: 05-07-2011, 10:25 AM
  3. Replies: 4
    Last Post: 04-07-2011, 03:39 PM
  4. Write Code to Navigate from Subform to Subform
    By Swilliams987 in forum Programming
    Replies: 22
    Last Post: 02-04-2011, 11:30 AM
  5. Replies: 1
    Last Post: 10-13-2010, 12:40 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