[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

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
   Me.Requery
   Set oRS = Me.RecordsetClone
   moSelect.RemoveAll
   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 !
0
rouxjean
Asked:
rouxjean
  • 2
  • 2
1 Solution
 
stevbeCommented:

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.

Steve
0
 
rouxjeanAuthor Commented:
Thanks ! This is weird...in Access97 it worked just great !
0
 
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 ?
0
 
stevbeCommented:
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?

Steve
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now