Results 1 to 3 of 3
  1. #1
    jerepois is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    16

    Changing the Datasheet recordsource of a split form

    I have a unbound combobox that uses a select case to change the recordsource of the form.



    here is the code that is powering the AfterUpdate() event.

    Code:
    Private Sub Combo2_AfterUpdate()    Select Case Me.Combo2.Column(1)
            Case "Scope Category"
                Me.RecordSource = "SELECT tblScopeCategory.[ScopeCategoryName] AS NAME, Count(tblWorkPackage.[WorkPackageID]) AS TOTAL" _
                & " FROM (tblCraft INNER JOIN (((tblWorkList INNER JOIN tblInScope ON tblWorkList.InScopeID = tblInScope.InScopeID) INNER JOIN tblWorkPackage ON tblWorkList.WorkPackageID = tblWorkPackage.WorkPackageID) INNER JOIN tblPlanner ON tblWorkPackage.PlannerID = tblPlanner.PlannerID) ON tblCraft.CraftID = tblWorkList.LeadCraftID) INNER JOIN tblScopeCategory ON tblWorkList.ScopeCategoryID = tblScopeCategory.ScopeCategoryID" _
                & " WHERE (((tblWorkList.AREA) Like " * ") AND ((tblInScope.InScopeName) Like " * ") AND ((tblPlanner.PlannerName) Like " * "))" _
                & " GROUP BY tblScopeCategory.[ScopeCategoryName];"
            Case "Equipment Category"
                Me.RecordSource = "SELECT tblWorkList.[EQUIPMENT_CATEGORY] AS NAME, Count(tblWorkPackage.[WorkPackageID]) AS TOTAL" _
                & " FROM (tblCraft INNER JOIN (((tblWorkList INNER JOIN tblInScope ON tblWorkList.InScopeID = tblInScope.InScopeID) INNER JOIN tblWorkPackage ON tblWorkList.WorkPackageID = tblWorkPackage.WorkPackageID) INNER JOIN tblPlanner ON tblWorkPackage.PlannerID = tblPlanner.PlannerID) ON tblCraft.CraftID = tblWorkList.LeadCraftID) INNER JOIN tblScopeCategory ON tblWorkList.ScopeCategoryID = tblScopeCategory.ScopeCategoryID" _
                & " WHERE (((tblWorkList.AREA) Like " * ") AND ((tblInScope.InScopeName) Like " * ") AND ((tblPlanner.PlannerName) Like " * "))" _
                & " GROUP BY tblWorkList.[EQUIPMENT_CATEGORY];"
            Case "Craft"
                Me.RecordSource = "SELECT tblCraft.[CraftName] AS NAME, Count(tblWorkPackage.[WorkPackageID]) AS TOTAL" _
                & " FROM (tblCraft INNER JOIN (((tblWorkList INNER JOIN tblInScope ON tblWorkList.InScopeID = tblInScope.InScopeID) INNER JOIN tblWorkPackage ON tblWorkList.WorkPackageID = tblWorkPackage.WorkPackageID) INNER JOIN tblPlanner ON tblWorkPackage.PlannerID = tblPlanner.PlannerID) ON tblCraft.CraftID = tblWorkList.LeadCraftID) INNER JOIN tblScopeCategory ON tblWorkList.ScopeCategoryID = tblScopeCategory.ScopeCategoryID" _
                & " WHERE (((tblWorkList.AREA) Like " * ") AND ((tblInScope.InScopeName) Like " * ") AND ((tblPlanner.PlannerName) Like " * "))" _
                & " GROUP BY tblCraft.[CraftName];"
        End Select
    End Sub
    I currently have NAME and TOTAL displaying in the Datasheet. Also the combo box is displaying in the datasheet view.

    Right now my issue is that when I make a selection from the combo box. The only change that happens in the datasheet is that the combo boxes field changes. I have attached two pictures to show what I mean.

    What I would like to do is completely reload the datasheet with the new recordsource. This is for display purposes only and not for information to be changed.

    Ive also tried the Me.Form.RecordSource still didn't update the datasheet.
    Click image for larger version. 

Name:	2.PNG 
Views:	8 
Size:	12.9 KB 
ID:	17777Click image for larger version. 

Name:	1.PNG 
Views:	8 
Size:	13.2 KB 
ID:	17778

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I just tested that and it worked for me. But did not use aggregate query and no table joins and no filter, just simple select.

    Probably the quotes around the * wildcard are an issue. Double them or use apostrophe and no spaces around the * wildcard:

    WHERE (((tblWorkList.AREA) Like '*') AND ((tblInScope.InScopeName) Like '*') AND ((tblPlanner.PlannerName) Like '*'))"

    But if you want all records, why bother with the WHERE clause?

    Suggest you start with simpler SQL statements.
    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
    jerepois is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    16
    Thanks June,

    Turns out it was just the quotes that was causing my issue. Now to clarify about the WHERE clause, I was adding in combo box selections for the where clause but I first needed to make sure the it worked and pulled everything first.

    all is working now. thank you.

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

Similar Threads

  1. Split Form with Datasheet on bottom
    By data808 in forum Queries
    Replies: 6
    Last Post: 02-19-2014, 03:05 PM
  2. Replies: 1
    Last Post: 02-03-2014, 03:06 PM
  3. changing recordsource
    By slimjen in forum Forms
    Replies: 1
    Last Post: 05-02-2013, 06:08 AM
  4. Datasheet view of Split Form in a Tab??
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 12-19-2011, 04:37 PM
  5. Changing A Report Recordsource from a form
    By warrenjburns in forum Reports
    Replies: 0
    Last Post: 04-09-2009, 05:38 AM

Tags for this Thread

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