PC Review


Reply
Thread Tools Rate Thread

cannot assign query to a Subform

 
 
Mangesh
Guest
Posts: n/a
 
      5th Aug 2010
Hi,

I created a form (Form1), and a subform within (Child85) i.e. its an
unbound subform. I then created a button on the form and put the
following code for the button:

sql1 = "Select * from MY_Table"
Form_Form1.Child85.Form.RecordSource = sql1
Form_Form1.Child85.Requery

However, when I click the button, I get the following error:

Run time error 2467
The expression you entered refers to an object that is colsed or
doesn't exist

What am I doing wrong? I checked a lot of threads but am not able to
get a solution for my problem.

- Mangesh
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      5th Aug 2010
On Thu, 5 Aug 2010 05:32:18 -0700 (PDT), Mangesh <(E-Mail Removed)>
wrote:

>Hi,
>
>I created a form (Form1), and a subform within (Child85) i.e. its an
>unbound subform. I then created a button on the form and put the
>following code for the button:
>
> sql1 = "Select * from MY_Table"
> Form_Form1.Child85.Form.RecordSource = sql1
> Form_Form1.Child85.Requery
>
>However, when I click the button, I get the following error:
>
> Run time error 2467
> The expression you entered refers to an object that is colsed or
>doesn't exist
>
>What am I doing wrong? I checked a lot of threads but am not able to
>get a solution for my problem.
>
>- Mangesh


Try

Forms!Form_Form1.Child85.Form.RecordSource = sql1
Forms!Form_Form1.Child85.Requery

explicitly referencing the Forms collection.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
Ron2006
Guest
Posts: n/a
 
      5th Aug 2010
Since (assuming) that the button is sitting on Form1 as is child85 I
would write the code as:

me.Child85.recordsource = sql1
me.Child85.requery

Ron
 
Reply With Quote
 
Mangesh
Guest
Posts: n/a
 
      5th Aug 2010
Thanks John, but now I get a new error:

Run time error 2450
Microsoft Office Access can't find the form Form_Form1referred to
in a macro expressionor visual basic code.
 
Reply With Quote
 
Mangesh
Guest
Posts: n/a
 
      5th Aug 2010
Thanks Ron,

But
me.Child85.recordsource = sql1
gives the error
Compile error: Method or data member not found

So changing it to
Me.Child85.Form.RecordSource = sql1
gives the earlier error
Run time error 2467 The expression you entered refers to an object
that is colsed or doesn't exist

And chaning it to
Me.Child85.SourceObject = sql1
gives the error
Runtime error 3011
The microsoft Jet database engine could not find the object
'~sq_cForm1~sq_cChild85'. Make sure the object exists and that you
spell its name and the path name correctly.

Stumped...!


>
> me.Child85.recordsource = sql1
> me.Child85.requery
>
> Ron


 
Reply With Quote
 
Mangesh
Guest
Posts: n/a
 
      5th Aug 2010
Also, please note that

MsgBox Me.Child85.Name

prints the name of the form. However

Me.Child85.SourceObject = sql1

erros out as mentioned in the previous post.
 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      5th Aug 2010
On Thu, 5 Aug 2010 08:26:00 -0700 (PDT), Mangesh <(E-Mail Removed)>
wrote:

>Thanks John, but now I get a new error:
>
> Run time error 2450
> Microsoft Office Access can't find the form Form_Form1referred to
>in a macro expressionor visual basic code.


Well, I can't see your screen, and you haven't posted the name of your form,
whether it is itself a subform, or the name of the subform control. The syntax
needs to be correct, and *I* don't know the names of the objects to put in the
expression! Could you give me some help?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      5th Aug 2010
John W. Vinson <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in
news:(E-Mail Removed):

> Try
>
> Forms!Form_Form1.Child85.Form.RecordSource = sql1
> Forms!Form_Form1.Child85.Requery
>
> explicitly referencing the Forms collection.


There is no need at all for a requery after changing the
recordsource, as the data returned will be exactly the same
(assuming, of course, that no data is added/deleted/edited between
assigning the recordsource and requerying it).

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/
 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      5th Aug 2010
Mangesh <(E-Mail Removed)> wrote in
news:b6e67131-0bdc-43ef-86a5-(E-Mail Removed)
:

> sql1 = "Select * from MY_Table"
> Form_Form1.Child85.Form.RecordSource = sql1
> Form_Form1.Child85.Requery


What about:

sql1 = "Select * from MY_Table"
Me!Child85.Form.RecordSource = sql1

Does that work?

(the requery is entirely redundant, as changing the recordsource
reloads the requested data already)

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/
 
Reply With Quote
 
Access Developer
Guest
Posts: n/a
 
      6th Aug 2010
"Mangesh" <(E-Mail Removed)> wrote

> Also, please note that
>
> MsgBox Me.Child85.Name
>
> prints the name of the form. However
>
> Me.Child85.SourceObject = sql1
>
> erros out as mentioned in the previous post.


A query or SQL statement is not a valid SourceObject for a Subform Control.

Create a text box, txtSeeIt, in the main form and try Me!txtSeeIt =
Me.Child85.SourceObject.

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access




--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access





 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign recordset - subform LisaB Microsoft Access Form Coding 1 6th Aug 2009 03:56 PM
subform assign value NetworkTrade Microsoft Access Forms 1 26th Mar 2008 02:26 PM
Can't assign value in subform =?Utf-8?B?SmVhbm5pZQ==?= Microsoft Access Forms 0 14th Aug 2007 06:28 PM
Cannot assign values in a subform =?Utf-8?B?Q1c=?= Microsoft Access Forms 3 29th Jun 2007 09:38 PM
Assign Recordset to Subform Help Brandon Johnson Microsoft Access Form Coding 5 20th Jun 2006 07:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:47 AM.