list boxes and queries in MSAcess 
Author Message
 list boxes and queries in MSAcess

I have a small problem at the moment.  (using MSAcess)
I have two forms.  On the first form, there is a texbox where a user can
enter a value, which gets used as a value for a parameter query.  On the
other form, I have a list box where I want the results of the query to
be displayed (after a command button is clicked on the other form)..

Does anyone know how I should be going about this.  Ive been trying to
use Recordsets, by putting the result of the query into a Recordset, and
setting the listbox to equal this. So far I have been unsuccessful.  Do
I need to use QueryDefs?

thanks for *any* help



Thu, 21 Mar 2002 03:00:00 GMT  
 list boxes and queries in MSAcess
Assuming the recordset for the listbox is set up correctly all you needdo is
requery the listbox

[list box name].requery

in the button click event

--
Hope this helps...

John Hawkins


Or see snippets of code and example access stuff at
http://www.btinternet.com/~vb


Quote:
> I have a small problem at the moment.  (using MSAcess)
> I have two forms.  On the first form, there is a texbox where a user can
> enter a value, which gets used as a value for a parameter query.  On the
> other form, I have a list box where I want the results of the query to
> be displayed (after a command button is clicked on the other form)..

> Does anyone know how I should be going about this.  Ive been trying to
> use Recordsets, by putting the result of the query into a Recordset, and
> setting the listbox to equal this. So far I have been unsuccessful.  Do
> I need to use QueryDefs?

> thanks for *any* help



Thu, 21 Mar 2002 03:00:00 GMT  
 list boxes and queries in MSAcess
Is it the initial query that's failing? If so, try this:
SQL = "Select Field1, Field2 .. From [My Table] "
SQL = SQL & "Where Fieldx = '" & Text1 & "'"
Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset)
Do While Not Rs.EOF
  List1.AddItem Rs("FieldName")
  Rs.MoveNext
Loop

Quote:

>I have a small problem at the moment.  (using MSAcess)
>I have two forms.  On the first form, there is a texbox where a user can
>enter a value, which gets used as a value for a parameter query.  On the
>other form, I have a list box where I want the results of the query to
>be displayed (after a command button is clicked on the other form)..

>Does anyone know how I should be going about this.  Ive been trying to
>use Recordsets, by putting the result of the query into a Recordset, and
>setting the listbox to equal this. So far I have been unsuccessful.  Do
>I need to use QueryDefs?

>thanks for *any* help

VB IRC for Intermediate to Advanced Users.
   Undernet   #vb-advanced


Thu, 21 Mar 2002 03:00:00 GMT  
 list boxes and queries in MSAcess
I think that's my problem - im trying to set up the recordset for the list box
on the other form, and I'm having trouble doing this.
Quote:

> Assuming the recordset for the listbox is set up correctly all you needdo is
> requery the listbox

> [list box name].requery

> in the button click event

> --
> Hope this helps...

> John Hawkins


> Or see snippets of code and example access stuff at
> http://www.btinternet.com/~vb



> > I have a small problem at the moment.  (using MSAcess)
> > I have two forms.  On the first form, there is a texbox where a user can
> > enter a value, which gets used as a value for a parameter query.  On the
> > other form, I have a list box where I want the results of the query to
> > be displayed (after a command button is clicked on the other form)..

> > Does anyone know how I should be going about this.  Ive been trying to
> > use Recordsets, by putting the result of the query into a Recordset, and
> > setting the listbox to equal this. So far I have been unsuccessful.  Do
> > I need to use QueryDefs?

> > thanks for *any* help



Fri, 22 Mar 2002 03:00:00 GMT  
 list boxes and queries in MSAcess
I think I almost have it working, except I keep getting errors when I try store
the results of a query into a recordset     ie:

Set SearchResults = Customer.OpenRecordset("Search")

*SearchResults is a recordset, Customer is the current db, and Search is the
queries who's results I wish to store.

The error I get is:    Run time error '3061',   Too few Parameters.  Expected 1.

The query (by itself) works fine.

Does anyone know what I am doing wrong?
thanks

Quote:

> I think that's my problem - im trying to set up the recordset for the list box
> on the other form, and I'm having trouble doing this.


> > Assuming the recordset for the listbox is set up correctly all you needdo is
> > requery the listbox

> > [list box name].requery

> > in the button click event

> > --
> > Hope this helps...

> > John Hawkins


> > Or see snippets of code and example access stuff at
> > http://www.btinternet.com/~vb



> > > I have a small problem at the moment.  (using MSAcess)
> > > I have two forms.  On the first form, there is a texbox where a user can
> > > enter a value, which gets used as a value for a parameter query.  On the
> > > other form, I have a list box where I want the results of the query to
> > > be displayed (after a command button is clicked on the other form)..

> > > Does anyone know how I should be going about this.  Ive been trying to
> > > use Recordsets, by putting the result of the query into a Recordset, and
> > > setting the listbox to equal this. So far I have been unsuccessful.  Do
> > > I need to use QueryDefs?

> > > thanks for *any* help



Fri, 22 Mar 2002 03:00:00 GMT  
 list boxes and queries in MSAcess
If you really have quotes around Search then you need a query called Search
in your database (by the way I suggest you use qrySearch for a name)
Or  if you have calculated a variable called Search that contains the query
string then you should use
Set SearchResults = Customer.OpenRecordset(Search)


Quote:
> I think I almost have it working, except I keep getting errors when I try
store
> the results of a query into a recordset     ie:

> Set SearchResults = Customer.OpenRecordset("Search")

> *SearchResults is a recordset, Customer is the current db, and Search is
the
> queries who's results I wish to store.

> The error I get is:    Run time error '3061',   Too few Parameters.
Expected 1.

> The query (by itself) works fine.

> Does anyone know what I am doing wrong?
> thanks


> > I think that's my problem - im trying to set up the recordset for the
list box
> > on the other form, and I'm having trouble doing this.


> > > Assuming the recordset for the listbox is set up correctly all you
needdo is
> > > requery the listbox

> > > [list box name].requery

> > > in the button click event

> > > --
> > > Hope this helps...

> > > John Hawkins


> > > Or see snippets of code and example access stuff at
> > > http://www.btinternet.com/~vb



> > > > I have a small problem at the moment.  (using MSAcess)
> > > > I have two forms.  On the first form, there is a texbox where a user
can
> > > > enter a value, which gets used as a value for a parameter query.  On
the
> > > > other form, I have a list box where I want the results of the query
to
> > > > be displayed (after a command button is clicked on the other form)..

> > > > Does anyone know how I should be going about this.  Ive been trying
to
> > > > use Recordsets, by putting the result of the query into a Recordset,
and
> > > > setting the listbox to equal this. So far I have been unsuccessful.
Do
> > > > I need to use QueryDefs?

> > > > thanks for *any* help



Fri, 22 Mar 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. list boxes and queries in MSAcess

2. Listing all tables or queries in a list/combo box

3. List Box - query selected item into table?

4. Passing multiple parameters to Access query using Form List Box

5. Selection of update queries from a list box

6. Running a parameter query from a selected record in a list box

7. Querying multiple items in a List Box

8. How to list macro names in a combo box or a list box

9. Can you use multiple items in a list box in a query

10. Help wanted with file list boxes and list boxes

11. VB List Box Versus Access List Box

12. How do I populate a list box with a passthrough query

 

 
Powered by phpBB® Forum Software