Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing a subform recordsource error

Posted on 2004-10-30
4
Medium Priority
?
479 Views
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
   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
Comment
Question by:rouxjean
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
stevbe earned 2000 total points
ID: 12451565

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
 

Author Comment

by:rouxjean
ID: 12451581
Thanks ! This is weird...in Access97 it worked just great !
0
 

Author Comment

by:rouxjean
ID: 12451612
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
 
LVL 39

Expert Comment

by:stevbe
ID: 12451687
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

604 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