PC Review


Reply
Thread Tools Rate Thread

display query result on subform

 
 
tracktraining
Guest
Posts: n/a
 
      29th Jul 2008
Hi ,

I have several queries that I already wrote. I am in the progress of
creating a user interface form. I want to call the queries and display the
results on a subform. I have written a short code (see below), but i keep
getting an error (Error Message: Run_time error '2467'. The expression you
entered refers to an object that is closed or doesn't exist). Is the code
below correct? Any suggestions/advices on how to make this work?

Private Sub Read_Click()
Dim qd As QueryDef
Set qd = CurrentDb.QueryDefs("SearchQuery")
qd.Parameters("Document ID") = Me.SearchDocID
Me.SearchResults.Form.RecordSource = "SearchQuery"
Me.SearchResults.Requery
End Sub


THANKS SO MUCH.
Tracktraining
--
Learning
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      29th Jul 2008
Your code creates an instance of the QueryDef, assigns the parameter, and
then doesn't do anything with it. Setting the RecordSource to the name of
the query doesn't use the QueryDef you created (which goes out of scope at
the end of the procedure.

It might be possible to name the parameter in the query to something like:
[Forms].[Form1].[SearchDocID]
Then just bind the subform to the query, and it will read the value from the
form.

If you always want to filter the form by the SearchDocID value, you could
simplify the whole process by omitting that parameter from the query.
Instead set the LinkMasterFields and LinkChildFields properties of the
subform control on your main form. No code is needed.

If there are actually lots of parameters you want to offer, this approach
might work:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
It builds the WHERE clause of the SQL statement dynamically, and then
filters the form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"tracktraining" <(E-Mail Removed)> wrote in message
news:33435E8B-0113-4885-AE96-(E-Mail Removed)...
>
> I have several queries that I already wrote. I am in the progress of
> creating a user interface form. I want to call the queries and display the
> results on a subform. I have written a short code (see below), but i keep
> getting an error (Error Message: Run_time error '2467'. The expression you
> entered refers to an object that is closed or doesn't exist). Is the code
> below correct? Any suggestions/advices on how to make this work?
>
> Private Sub Read_Click()
> Dim qd As QueryDef
> Set qd = CurrentDb.QueryDefs("SearchQuery")
> qd.Parameters("Document ID") = Me.SearchDocID
> Me.SearchResults.Form.RecordSource = "SearchQuery"
> Me.SearchResults.Requery
> End Sub
>
>
> THANKS SO MUCH.
> Tracktraining
> --
> Learning


 
Reply With Quote
 
tracktraining
Guest
Posts: n/a
 
      30th Jul 2008
Thanks so much. Your database was very helpful.
--
Learning


"Allen Browne" wrote:

> Your code creates an instance of the QueryDef, assigns the parameter, and
> then doesn't do anything with it. Setting the RecordSource to the name of
> the query doesn't use the QueryDef you created (which goes out of scope at
> the end of the procedure.
>
> It might be possible to name the parameter in the query to something like:
> [Forms].[Form1].[SearchDocID]
> Then just bind the subform to the query, and it will read the value from the
> form.
>
> If you always want to filter the form by the SearchDocID value, you could
> simplify the whole process by omitting that parameter from the query.
> Instead set the LinkMasterFields and LinkChildFields properties of the
> subform control on your main form. No code is needed.
>
> If there are actually lots of parameters you want to offer, this approach
> might work:
> Search form - Handle many optional criteria
> at:
> http://allenbrowne.com/ser-62.html
> It builds the WHERE clause of the SQL statement dynamically, and then
> filters the form.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "tracktraining" <(E-Mail Removed)> wrote in message
> news:33435E8B-0113-4885-AE96-(E-Mail Removed)...
> >
> > I have several queries that I already wrote. I am in the progress of
> > creating a user interface form. I want to call the queries and display the
> > results on a subform. I have written a short code (see below), but i keep
> > getting an error (Error Message: Run_time error '2467'. The expression you
> > entered refers to an object that is closed or doesn't exist). Is the code
> > below correct? Any suggestions/advices on how to make this work?
> >
> > Private Sub Read_Click()
> > Dim qd As QueryDef
> > Set qd = CurrentDb.QueryDefs("SearchQuery")
> > qd.Parameters("Document ID") = Me.SearchDocID
> > Me.SearchResults.Form.RecordSource = "SearchQuery"
> > Me.SearchResults.Requery
> > End Sub
> >
> >
> > THANKS SO MUCH.
> > Tracktraining
> > --
> > Learning

>
>

 
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
Pass Result From Query to a field on a subform =?Utf-8?B?Um9u?= Microsoft Access Queries 5 9th Nov 2005 01:51 AM
total result of query less than 10K an display as 1 result =?Utf-8?B?RG9ubmEuSy4=?= Microsoft Access Queries 2 20th Oct 2005 01:46 PM
refresh query result in subform programmatically from main form =?Utf-8?B?RXJpYw==?= Microsoft Access Form Coding 0 23rd Sep 2005 06:26 PM
Updating a query result in subform John Doe Microsoft Access Forms 1 19th Nov 2004 02:18 AM
different query result per record in subform Chris Microsoft Access Forms 0 27th Nov 2003 06:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:12 PM.