Results 1 to 5 of 5
  1. #1
    accessbro is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    23

    Change subform sourceobject and go to specific record in subform by ID

    I have a main form with a continuous form as the source object in the subform control. There's a button on the continuous subform that changes the subform source object to a single form but when the subform source object is changed, it always goes to the first record in the single form. I want the single subform to show the record with the same ID as the record in the continuous form. I have tried:

    Forms![Main Form]![Subform].Form.SourceObject = "singleSubForm"
    Forms![Main Form]![Subform].Form.Filter = "[ID]=" & Me![ID]
    Forms![Main Form]![Subform].Form.FilterOn = true

    Forms![Main Form]![Subform].Form.SourceObject = "singleSubForm"
    With Forms![Main Form]![Subform].Form.Recordset
    .FindFirst "ID=" & Me![ID]
    End With



    Forms![Main Form]![SubForm].Form.SourceObject = "singleSubForm"
    Forms![Main Form]![Subform].Form.RecordSource = "SELECT * FROM Query1 WHERE [ID] =" & Me![ID]

    How can I make it so that when I click on the button in the record in continuous subform, the subform source object changes to a single form and goes to the record with the same ID as the record in the continuous form where the user pressed the button?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    SourceObject is a property of the subform container, not the form held by the container. Is Subform actually the name of the container?

    Me.Parent.[subformcontainername].SourceObject = "singleSubForm"


    Do you really need to change the SourceObject property? Are there really two different forms? Or do you just need to change the DefaultView property of the form object?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    accessbro is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    23
    Technically the name of the subform container is something like Child27 right now.

    I'm experimenting with my form design where everything is displayed in a subform in the main navigation form. The continuous form and subform record source are based on the same query but the single form provides more details. I want the user to be able to click on the record in the continuous form so that the subform displays the record with more detail. My approach was by changing it to the single form but it always goes to the first record. I want it to go to the record with the same ID as the continuous form record.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I just tested trying to change DefaultView property. Requires form to be open in Design. Scrap that idea.



    First set a variable with the ID value.

    intID = Me!ID
    Forms![Main Form].Child27.SourceObject = "singleSubForm"
    Forms![Main Form].Child27.Form.Filter = "[ID]=" & intID
    Forms![Main Form].Child27.Form.FilterOn = True

    Alternatively, button can be in the main form.
    intID = Me.Child27!ID
    Me.Child27.SourceObject = "singleSubForm"
    Me.Child27.Form.Filter = "[ID]=" & intID
    Me.Child27.Form.FilterOn = True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    accessbro is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    23
    I figured it out. singleSubform is actually the subform in the form that's used in the subform in the main form.

    Forms![Main Form].Child27.Form.Child0.Form.Filter = "[ID]=" & intID
    Forms![Main Form].Child27.Form.Child0.Form.FilterOn = True

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

Similar Threads

  1. Replies: 1
    Last Post: 01-12-2015, 01:32 PM
  2. Replies: 9
    Last Post: 11-21-2014, 07:06 PM
  3. Replies: 29
    Last Post: 01-29-2014, 01:04 PM
  4. Replies: 5
    Last Post: 10-11-2013, 04:33 PM
  5. pull data from a specific record in a subform
    By pleshrl in forum Queries
    Replies: 3
    Last Post: 04-21-2013, 05:07 AM

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