Changing a subform recordsource error

Posted on 2004-10-30
Last Modified: 2009-07-29
Hi !
From the main form, I am trying to change the subform recordsource with the following code (that resides in the subform) :
Public Sub SetSource(pSQL As String)
   Dim i As Integer
   Dim oRS As DAO.Recordset
   Me.RecordSource = pSQL
   Set oRS = Me.RecordsetClone
   Me.Controls("UPC").ControlSource = oRS.Fields(1).Name
End Sub
I'm using this line to do the job from the main form (I'm actually calling the subform's sub) :
Me.SubSelection.Form.SetSource strSQL
When I run the code I have this error :"Method 'Form' of object '_Subform' failed. It crash on the line I use to call the subform's sub.
Form name : frmSelection
Subform component name: SubSelection
Subform form name: frmSubSelection
Please help !
Question by:rouxjean
    LVL 39

    Accepted Solution


    Form_NameOfSubFOrm.SetSource strSQL

    in this case you are calling code and need the absolute reference so you would use the actual name of the subform (not the subform control) and use the Form_   prefix just like it shows in the project explorer when you are in the IDE.


    Author Comment

    Thanks ! This is Access97 it worked just great !

    Author Comment

    OMG...why is this always happening to me ?
    Now on the same line, without changing any code, it now says Object Variable or With block not set !
    I tried : Form_frmSubSelection.SetSource strSQL
    Any ideas ?
    LVL 39

    Expert Comment

    when you type Form_frmSubSelection.   do you get a drop list after type the period (.)   ?

    Does it compile?

    If you always run this from the main form why not put the code directly in the main form?

    If you step through the code is it failing in the inital call is the error happening inside the SetSource code itself?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Cisco Complete Network Certification Training

    If you’re an IT engineer or technician, it's time you take your career to the next level. This elite training bundle is brimming with all of the information you need to learn to sit for Cisco CNNA, CCNP, and CCENT certification exams.

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now