Changing a subform recordsource error

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 !
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rouxjeanAuthor Commented:
Thanks ! This is Access97 it worked just great !
rouxjeanAuthor Commented:
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 ?
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?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.