Results 1 to 4 of 4
  1. #1
    crxftw is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    30

    Setting 2 RecordSources for a subforms form depending on field in mainform


    Hello. I'm looking for a solution how I can have 2 RecordSources for a form that's SourceObject in my mainforms subform. It needs to choose one of the 2 queries depending on the value that is in hidden field in my mainform.

    In my database when I open mainform, then in a subform I need to get results based on first query 'qrySalesComplete' if "txtStatusID > 20" and if it's anything else, zero in this case, then I need the query to be 'qrySalesInvoiced'. Not sure if it's possible to change RecordSource for a form SourceObject for subform. Do I need to have 2 different forms then with different queries and change the SourceObject for subform then depending on the field value?

    I've tried to look anywhere but can't find a proper solution for that and not sure if it's the best idea to solve this problem.

    Regards.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can set the recordsource:

    Me.RecordSource = "QueryName"

    Replacing "Me" with a full reference if appropriate. Sounds like you'd want to do it in the after update event of the textbox that will change, and/or the current event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    crxftw is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    30
    I need it to display data when I open up the main form, txtStatusID is already set when opening it up, while creating an invoice its value is set to 0 by default, then I need to display data in subform, which has continuous form linked to it, that belong to the Client I choose from above from dropdown, subform has master and child fields set to their primary key ID which should return data that for the client who was selected. But when an old invoice, which is just submitted, is opened up then StatusID is already set to 100 (if submitted) and 200 (if marked paid, think i mentioned wrong number above but it doesn't matter). And now I need the subform to display me results that are returned from another query, where specific sales are linked to that invoice. Hope it makes sense.

    I tried this in main forms Form OnLoad:

    Code:
    With sbfSalesComplete.Form 
        If txtStatusID.Value > 100 Then
            .RecordSource = "qrySalesComplete"
        Else
            .RecordSource = "qrySalesInvoiced"
        End If
    End With
    but I am not getting anything, tried to add different values to watchlist while debugging it in vba editor and nothing.

    Then I also switched things around and made 2 new continuous forms, one with qrySalesCompleted record source and another with qrySalesInvoiced. Then to OnLoad I added:

    Code:
    If txtStatusID.Value > 100 Then
         Me.sbfSalesComplete.SourceObject = "frmCompletedSales"
    Else
         Me.sbfSalesComplete.SourceObject = "frmCompletedInvoices"
    End If
    ..and I am getting nothing. Not sure where the problem is, not very familiar with access too. Tried to add requery after every setting too.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Personally I'd use a full form reference or Me to avoid ambiguity. Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 04-04-2011, 02:18 PM
  2. Form Field Default Setting
    By roofbid in forum Programming
    Replies: 3
    Last Post: 12-17-2010, 10:53 AM
  3. Setting Recordsource for Subforms
    By P5C768 in forum Forms
    Replies: 5
    Last Post: 11-16-2010, 05:01 AM
  4. Return blank field depending on quantity
    By anthonyjf in forum Access
    Replies: 1
    Last Post: 04-01-2009, 08:22 AM
  5. Replies: 0
    Last Post: 03-16-2006, 04:59 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