Results 1 to 5 of 5
  1. #1
    Huron is offline Novice
    Windows 10 Access 2003
    Join Date
    Mar 2021
    Posts
    21

    How to change the RecordSource in the query from the main form...?

    Maybe someone had such a problem...?
    Attached Thumbnails Attached Thumbnails Query-Err-2.jpg  

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    Maybe you should state what you're trying to do in simple terms rather than just show what's not working. I see so many possible issues there, mainly that you cannot set a form recordsource to something like "T12". It has to be either a valid sql statement or the name of a query or a variable that holds one of those. If it were a variable, you would not enclose it in quotes. So that's 2 issues. The message is saying it can't find a field named T12. That's another. A query is not a member of a form collection, so that's another. It's usually done along the lines of

    If this Then
    Me.Recordsource = "SELECT * FROM tbl1..."
    Else
    Me.Recordsource = "SELECT * FROM tbl2..."
    End IF
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Huron is offline Novice
    Windows 10 Access 2003
    Join Date
    Mar 2021
    Posts
    21

    Question RecordSource

    I want to change from the MainForm RecordSource in query Q12....
    Attached Files Attached Files

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,411
    Code on main form wants to change property of its subform, so like this:
    [ml-sub] is name of control on main form holding the subform.

    Code:
    Private Sub BookType_AfterUpdate()
        If Me.[BookType] = "Table-1" Then
            Me![ml-sub].Form.RecordSource = "SELECT * FROM Q1"
        Else
            Me![ml-sub].Form.RecordSource = "SELECT * FROM Q2"
        End If
    End Sub
    ml-sub is a bad name to use. Access could construe it to be expression ml minus sub. Better would be mlsub or ml_sub.
    Last edited by davegri; 03-05-2021 at 12:58 PM. Reason: more

  5. #5
    Huron is offline Novice
    Windows 10 Access 2003
    Join Date
    Mar 2021
    Posts
    21
    Quote Originally Posted by davegri View Post
    Code on main form wants to change property of its subform, so like this:
    [ml-sub] is name of control on main form holding the subform.

    Code:
    Private Sub BookType_AfterUpdate()
        If Me.[BookType] = "Table-1" Then
            Me![ml-sub].Form.RecordSource = "SELECT * FROM Q1"
        Else
            Me![ml-sub].Form.RecordSource = "SELECT * FROM Q2"
        End If
    End Sub
    ml-sub is a bad name to use. Access could construe it to be expression ml minus sub. Better would be mlsub or ml_sub.

    Thank you very much...

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

Similar Threads

  1. Replies: 10
    Last Post: 07-05-2017, 11:31 AM
  2. Replies: 23
    Last Post: 07-15-2016, 03:15 PM
  3. Replies: 2
    Last Post: 12-07-2014, 01:15 PM
  4. Replies: 1
    Last Post: 04-25-2011, 12:20 PM
  5. Change RecordSource in Tabbed Subforms
    By matchorno in forum Access
    Replies: 4
    Last Post: 03-09-2011, 09:12 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