Results 1 to 9 of 9
  1. #1
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29

    Changing Subform RecordSource Programmatically

    I'm having issues changing a subform's record source programmatically. I have a subform with a list of projects that a staff member is allocated to, but I've gotten a request to also have a view of all a project list.



    I thought I could just have a command button to change the record source to another query, but every time I do that I get either an error or a table open error. Their are also master/child links, but the fields have the same names in both queries (not sure if it matters).

    Edit:
    Side question: Is it possible to make a form into a class that can be invoked programmatically?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Not sure what you mean by 'view of all a project list'. You want to show all projects not just that staff member's? Yes, the Master/Child links will prevent that if the links are on StaffID.
    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
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29
    Quote Originally Posted by June7 View Post
    Not sure what you mean by 'view of all a project list'. You want to show all projects not just that staff member's? Yes, the Master/Child links will prevent that if the links are on StaffID.
    Basically I have two queries. One that shows a list of the projects a staff is allocated for, and another that just shows the whole project list. Whenever I try to change the subform's source I get errors.

    Here is what I'm trying to do currently:
    Code:
        Me!fsubTSResAlloc.Form.RecordSource = "QRY_TS_All"
        Me!fsubTSResAlloc.Form.LinkChildFields = ""
        Me!fsubTSResAlloc.Form.LinkMasterFields = ""
        Me.fsubTSResAlloc.Form.Requery
    I'm not really sure how to progress, and feel like I'm screwing up the syntax somehow.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    The Master/Child links are properties of the subform container, not the form object. I always name subform containers different from the object they hold, like ctrAlloc. Then code:

    Me.ctrAlloc.LinkChildFields = ""
    Me.ctrAlloc.LinkMasterFields = ""
    Me.ctrAlloc.Form.RecordSource = "QRY_TS_All"
    Me.ctrAlloc.Requery
    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
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29
    Thanks for your reply. Running the code I get a "table is already opened exclusively by another user" error. The only user in the system is me and I have no other components open. This is happening when I just try to run the link codes as well, so I'm not sure what's going on here.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    I have never tried programatically setting links and recordsource of subform. Might not be possible unless in Design view. If you want to provide project I will analyze.
    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.

  7. #7
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29
    Quote Originally Posted by June7 View Post
    I have never tried programatically setting links and recordsource of subform. Might not be possible unless in Design view. If you want to provide project I will analyze.
    Unfortunately I can't provide the DB as there is too much data in it that can't be shared. I tried to strip down and make a barebones version but it was clear pretty quick I'd have to change a lot of data to be able to do that while still having the form functional.

    Perhaps I should try another methodology; maybe a hidden linked field would be a better way?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    I just did a quick test of code resetting Links and RecordSource and it did work. I did not use a saved Access query object as the RecordSource. I built the SQL in the code.
    Me.ctrSections.Form.RecordSource = "SELECT * FROM Strength;"

    Have you step debugged?
    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.

  9. #9
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29
    I have step debugged and I get the open table error when trying to change the child or master links; not sure why.

    Edit: Found the issue; I forgot to disable record locks on the project list (since there is no need to edit it).

    Edit 2: Now everything is working perfect. Thanks for your help!

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

Similar Threads

  1. Replies: 3
    Last Post: 01-05-2012, 10:47 AM
  2. Replies: 3
    Last Post: 01-04-2012, 05:16 PM
  3. Update Subform Recordsource
    By mystifier in forum Forms
    Replies: 8
    Last Post: 11-15-2010, 03:03 AM
  4. update recordsource of subform
    By AndyKim in forum Forms
    Replies: 1
    Last Post: 06-16-2009, 09:15 AM
  5. Changing A Report Recordsource from a form
    By warrenjburns in forum Reports
    Replies: 0
    Last Post: 04-09-2009, 05:38 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