Results 1 to 3 of 3
  1. #1
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211

    Query button on form to open results on subform

    I have multiple query buttons on one form. I have a datasheet subform that is a datasheet form itself (dragged and dropped onto main form). I did not bound/bind the subform to anything. I would like to update that datasheet subform based on clicking a button that is bound to a query. It almost wants to function but does not show any results. The purpose of this is for administrative things and not users entering data, as they will not see this function in their view.



    The following is screenshot of wanting to append records (note grey with asterisk) when clicking query button but shows nothing and creates a separate datasheet tab outside of form:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	10 
Size:	12.1 KB 
ID:	32150

    The following code is the button:

    Private Sub btnQueryCase_Click()
    On Error GoTo btnQueryCase_Click_Err
    DoCmd.OpenQuery "qlkpCase", acViewNormal, acEdit
    Me.subfrmQueryAll.Form.RecordSource = "qlkpCase"
    Me.subfrmQueryAll.Form.Requery
    btnQueryCase_Click_Exit:
    Exit Sub
    btnQueryCase_Click_Err:
    MsgBox Err.Description, vbOKOnly, ""
    Resume btnQueryCase_Click_Exit
    End Sub

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    You are opening the query, that's why it is appearing in a separate window. You don't need to.

    Also It's not the RecordSource you need to change in the sub form - it's the SourceObject.

    Try setting the source object to "query.qlkpCase"
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    That did the trick. It is one of those things were you try one thousand variables but it is the one someone else recommends, and makes sense, that functions as intended. The following is the adjusted code (red) for anyone interested.

    Private Sub btnQueryCase_Click()
    On Error GoTo btnQueryCase_Click_Err
    Me.subfrmQueryAll.SourceObject = "query.qlkpCase"
    btnQueryCase_Click_Exit:
    Exit Sub
    btnQueryCase_Click_Err:
    MsgBox Err.Description, vbOKOnly, ""
    Resume btnQueryCase_Click_Exit
    End Sub

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

Similar Threads

  1. Button open selected record in subform table, in new form
    By BrainExplodingFromCoffee in forum Forms
    Replies: 4
    Last Post: 04-12-2016, 02:19 PM
  2. Replies: 9
    Last Post: 11-16-2014, 12:12 AM
  3. Replies: 1
    Last Post: 07-20-2012, 09:48 AM
  4. Replies: 4
    Last Post: 03-01-2012, 08:15 PM
  5. Open form based on query results
    By RobbertH in forum Queries
    Replies: 1
    Last Post: 02-10-2010, 08:13 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