• Changing the Sourceobject of a subform…

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Changing the Sourceobject of a subform…

    Author
    Topic
    #468703

    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?

    Viewing 4 reply threads
    Author
    Replies
    • #1222181

      Try

      Code:
      Me!FrmSubResult.SourceObject = "TempQuery"
    • #1222185

      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?

    • #1222201

      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

    • #1222209

      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.

    • #1222233

      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!

    Viewing 4 reply threads
    Reply To: Changing the Sourceobject of a subform…

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: