Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Mar 2010
    Location
    UK
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right, me again guys!

    This one seems simple, but i cant seem to get it to work.

    I have put together a basic query builder on a dialog form, which is opened by a button on the main form (Form 1).

    So the user would click the button on Form 1, it would open the querybuilder, (Form 2) once the query has been written and "Generate" button has been clicked, Form 2 has the button with all the code basicall.

    When the button on form 2 is clicked it should alter the source object of the subform on form 1, and then requery it.

    below is the cod efor that part

    Code:
    DoCmd.Close acForm, "frm_SYS_QryBuilder"
    
    'Change FrmSubResult course object to the new Query and Refresh
    Me!FrmSubResult.SourceObject = "Query.TempQuery"
    
            'Needed to check value, will not be in release version
            strSource = Me!FrmSubResult.SourceObject
    
    Me!FrmSubResult.Form.Requery
    I have googled, and other people have had similar problems, but i couldnt find a solution that helped.

    Can anyone help?

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Try

    Code:
    Me!FrmSubResult.SourceObject = "TempQuery"
    Regards
    John



  3. #3
    Lounger
    Join Date
    Mar 2010
    Location
    UK
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesnt work.

    The code i posted i actually have workign on another form (form 1) using the me.frmsubresult rather than me!frmsubresult

    I noted that when i changed the sourceobject manually i had to put a prefix infront of the name so it knew what it was showing, so i altered my code accordingly.

    I am correct in assuming that ! reffers to another opened item?

  4. #4
    Star Lounger
    Join Date
    Sep 2002
    Location
    Hastings, Sussex, England
    Posts
    67
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Christopher.

    You posted: When the button on form 2 is clicked it should alter the source object of the subform on form 1, and then requery it.

    Your code uses 'Me' which only refers to the current form. You need to explicitly refer to the first form, as an object in the Forms collection. Try using forms!formname!frmsubresult.sourceobject

    Regards,

    Jules

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Sorry.
    I was mixing up "Source Object" and "Control Source"...I did not realise that you were just displaying the query directly. I had imagined you were displaying the query results within a form , and so you were changing the Record Source of the form.

    I think Jules has found the problem, with the use of me.

    Another approach is to leave the Source Object unchanged, but just use the query builder to change the SQL of the one query.
    Regards
    John



  6. #6
    Lounger
    Join Date
    Mar 2010
    Location
    UK
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm such a newb!

    That fixed it! Thank you, id like to say i wont make that mistake again, but id actually come accross that on a previous project and forgot all about it by the time i got to needing this today.

    for all!

    Thank you Jules and John!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •