Select where statement in a series of queries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to use a select where statement in a which the I have a series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A WHERE [date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several intermediate
queries but I don't think that matters?
 
There might be a better solution depending on your exact situation, but you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.
 
Not really following this reply. Just so you understand better what I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value of [a]
for each . I would like some times to have the code avg only by a set of
dates (say Aug and Sept) based on a text box. Since my final query [A] does
not have a date field, nor could it, to have the corrrect out put. How can I
preselect out only Aug and Sept dates based on text box input. I was hoping
to have a WHERE statement that would be temporarly inserted into underlining
query so that the final query would give the desire output but then remove
the WHERE statement afterwords so that a different set of dates could be
evaluated. I know it may seem like the easy way would be to setup a seperate
underling query but the whole series if very complicated and it seems like
code could do this.
David McKnight


Rob Oldfield said:
There might be a better solution depending on your exact situation, but you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.


David McKnight said:
I would like to use a select where statement in a which the I have a series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A WHERE [date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several intermediate
queries but I don't think that matters?
 
Yes. That's what I thought you had. The idea is that if your final query A
is based on another query B which is based on another query C, then you can
use my example to modify the SQL of C (so limiting it to whatever date range
you wish), and then use query A.


David McKnight said:
Not really following this reply. Just so you understand better what I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value of [a]
for each . I would like some times to have the code avg only by a set of
dates (say Aug and Sept) based on a text box. Since my final query [A] does
not have a date field, nor could it, to have the corrrect out put. How can I
preselect out only Aug and Sept dates based on text box input. I was hoping
to have a WHERE statement that would be temporarly inserted into underlining
query so that the final query would give the desire output but then remove
the WHERE statement afterwords so that a different set of dates could be
evaluated. I know it may seem like the easy way would be to setup a seperate
underling query but the whole series if very complicated and it seems like
code could do this.
David McKnight


Rob Oldfield said:
There might be a better solution depending on your exact situation, but you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.


I would like to use a select where statement in a which the I have a series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A WHERE [date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several intermediate
queries but I don't think that matters?
 
Sorry if I'm taking you code too verbatim, but this is how I translated into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof]. With is coed I
get a run time error of 3265, Item not found in collection. this is on
lineSet qdf=....
--
David McKnight


Rob Oldfield said:
Yes. That's what I thought you had. The idea is that if your final query A
is based on another query B which is based on another query C, then you can
use my example to modify the SQL of C (so limiting it to whatever date range
you wish), and then use query A.


David McKnight said:
Not really following this reply. Just so you understand better what I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value of [a]
for each . I would like some times to have the code avg only by a set of
dates (say Aug and Sept) based on a text box. Since my final query [A] does
not have a date field, nor could it, to have the corrrect out put. How can I
preselect out only Aug and Sept dates based on text box input. I was hoping
to have a WHERE statement that would be temporarly inserted into underlining
query so that the final query would give the desire output but then remove
the WHERE statement afterwords so that a different set of dates could be
evaluated. I know it may seem like the easy way would be to setup a seperate
underling query but the whole series if very complicated and it seems like
code could do this.
David McKnight


Rob Oldfield said:
There might be a better solution depending on your exact situation, but you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.


I would like to use a select where statement in a which the I have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several intermediate
queries but I don't think that matters?

 
That should work (although the SQL text isn't right yet). The error that
you're getting is basically saying that it can't find a query called Query
C.

What does this give you?

Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
for each qdf in db.querydefs
msgbox qdf.name
next
Set qdf = Nothing
Set db = Nothing


David McKnight said:
Sorry if I'm taking you code too verbatim, but this is how I translated into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof]. With is coed I
get a run time error of 3265, Item not found in collection. this is on
lineSet qdf=....
--
David McKnight


Rob Oldfield said:
Yes. That's what I thought you had. The idea is that if your final query A
is based on another query B which is based on another query C, then you can
use my example to modify the SQL of C (so limiting it to whatever date range
you wish), and then use query A.


Not really following this reply. Just so you understand better what I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value of [a]
for each . I would like some times to have the code avg only by a
set
of
dates (say Aug and Sept) based on a text box. Since my final query [A] does
not have a date field, nor could it, to have the corrrect out put. How
can
I
preselect out only Aug and Sept dates based on text box input. I was hoping
to have a WHERE statement that would be temporarly inserted into underlining
query so that the final query would give the desire output but then remove
the WHERE statement afterwords so that a different set of dates could be
evaluated. I know it may seem like the easy way would be to setup a seperate
underling query but the whole series if very complicated and it seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact situation,
but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.


I would like to use a select where statement in a which the I have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several intermediate
queries but I don't think that matters?
 
Oops, had a spelling error so "Query C" line is okay. However, having
problems with the next line getting syntax correct.
--
David McKnight


David McKnight said:
Sorry if I'm taking you code too verbatim, but this is how I translated into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof]. With is coed I
get a run time error of 3265, Item not found in collection. this is on
lineSet qdf=....
--
David McKnight


Rob Oldfield said:
Yes. That's what I thought you had. The idea is that if your final query A
is based on another query B which is based on another query C, then you can
use my example to modify the SQL of C (so limiting it to whatever date range
you wish), and then use query A.


David McKnight said:
Not really following this reply. Just so you understand better what I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value of [a]
for each . I would like some times to have the code avg only by a set of
dates (say Aug and Sept) based on a text box. Since my final query [A] does
not have a date field, nor could it, to have the corrrect out put. How can I
preselect out only Aug and Sept dates based on text box input. I was hoping
to have a WHERE statement that would be temporarly inserted into underlining
query so that the final query would give the desire output but then remove
the WHERE statement afterwords so that a different set of dates could be
evaluated. I know it may seem like the easy way would be to setup a seperate
underling query but the whole series if very complicated and it seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact situation, but you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.


I would like to use a select where statement in a which the I have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several intermediate
queries but I don't think that matters?

 
It will be something like Klatuu posted in your other thread...

qdf.Sql= "SELECT [table A] WHERE Month([DATEOf]) = 8;"



David McKnight said:
Oops, had a spelling error so "Query C" line is okay. However, having
problems with the next line getting syntax correct.
--
David McKnight


David McKnight said:
Sorry if I'm taking you code too verbatim, but this is how I translated into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof]. With is coed I
get a run time error of 3265, Item not found in collection. this is on
lineSet qdf=....
--
David McKnight


Rob Oldfield said:
Yes. That's what I thought you had. The idea is that if your final query A
is based on another query B which is based on another query C, then you can
use my example to modify the SQL of C (so limiting it to whatever date range
you wish), and then use query A.


Not really following this reply. Just so you understand better what I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value of [a]
for each . I would like some times to have the code avg only by a set
of
dates (say Aug and Sept) based on a text box. Since my final query [A]
does
not have a date field, nor could it, to have the corrrect out put. How can
I
preselect out only Aug and Sept dates based on text box input. I was
hoping
to have a WHERE statement that would be temporarly inserted into
underlining
query so that the final query would give the desire output but then remove
the WHERE statement afterwords so that a different set of dates could be
evaluated. I know it may seem like the easy way would be to setup a
seperate
underling query but the whole series if very complicated and it seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact situation, but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.


message
I would like to use a select where statement in a which the I have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several
intermediate
queries but I don't think that matters?
 
When I use this code I get a missing operator error. One thing I don't get
that I'm trying to achieve from the below statement is flexiblity to specify
a month/day combination , say all days between 9/12 & 11/12 for any given
year.
--
David McKnight


Rob Oldfield said:
It will be something like Klatuu posted in your other thread...

qdf.Sql= "SELECT [table A] WHERE Month([DATEOf]) = 8;"



David McKnight said:
Oops, had a spelling error so "Query C" line is okay. However, having
problems with the next line getting syntax correct.
--
David McKnight


David McKnight said:
Sorry if I'm taking you code too verbatim, but this is how I translated into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof]. With is coed I
get a run time error of 3265, Item not found in collection. this is on
lineSet qdf=....
--
David McKnight


:

Yes. That's what I thought you had. The idea is that if your final query A
is based on another query B which is based on another query C, then you can
use my example to modify the SQL of C (so limiting it to whatever date range
you wish), and then use query A.


Not really following this reply. Just so you understand better what I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value of [a]
for each . I would like some times to have the code avg only by a set
of
dates (say Aug and Sept) based on a text box. Since my final query [A]
does
not have a date field, nor could it, to have the corrrect out put. How can
I
preselect out only Aug and Sept dates based on text box input. I was
hoping
to have a WHERE statement that would be temporarly inserted into
underlining
query so that the final query would give the desire output but then remove
the WHERE statement afterwords so that a different set of dates could be
evaluated. I know it may seem like the easy way would be to setup a
seperate
underling query but the whole series if very complicated and it seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact situation, but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.


message
I would like to use a select where statement in a which the I have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several
intermediate
queries but I don't think that matters?

 
Oops. I missed that Klatuu's suggestion wasn't right. Allen's, however, is
OK...

"SELECT [table A].* FROM [table A] WHERE Month([table A].[DATEOf])=8;" would
give you just August.

With regard to the flexibility, that's a bit of 'how long is a piece of
string' type question. Let's assume that you want the user to be able to
enter two dates and just limit the data to dates between those. The best
way to approach this is to just go to a query window and set it up (using
any two dates). You can then use the View, SQL View command to see the sql
text for that query. That will look something like...

SELECT [Table A].*
FROM [Table A]
WHERE ((([Table A].DateOf)>=#1/1/2005# And ([Table
A].DateOf)<=#1/10/2005#));

so that's the text that you'd need to build, replacing the dummy dates with
the dates that the user has entered. So maybe...

qdf.sql="SELECT [Table A].* "+ _
"FROM [Table A] "+ _
"WHERE ((([Table A].DateOf)>=#"+ _
forms![DateInput]![StartDate]+"# And ([Table A].DateOf)<=#"+ _
forms![DateInput]![EndDate]+"#));"

There's another issue there if you use dd/mm/yyyy format dates. But we'll
worry about that later.




David McKnight said:
When I use this code I get a missing operator error. One thing I don't get
that I'm trying to achieve from the below statement is flexiblity to specify
a month/day combination , say all days between 9/12 & 11/12 for any given
year.
--
David McKnight


Rob Oldfield said:
It will be something like Klatuu posted in your other thread...

qdf.Sql= "SELECT [table A] WHERE Month([DATEOf]) = 8;"



Oops, had a spelling error so "Query C" line is okay. However, having
problems with the next line getting syntax correct.
--
David McKnight


:

Sorry if I'm taking you code too verbatim, but this is how I
translated
into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof]. With
is
coed I
get a run time error of 3265, Item not found in collection. this is on
lineSet qdf=....
--
David McKnight


:

Yes. That's what I thought you had. The idea is that if your
final
query A
is based on another query B which is based on another query C,
then
you can
use my example to modify the SQL of C (so limiting it to whatever
date
range
you wish), and then use query A.


"David McKnight" <[email protected]> wrote
in
message
Not really following this reply. Just so you understand better
what
I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg
value
of [a]
for each . I would like some times to have the code avg only
by
a set
of
dates (say Aug and Sept) based on a text box. Since my final
query
[A]
does
not have a date field, nor could it, to have the corrrect out
put.
How can
I
preselect out only Aug and Sept dates based on text box input. I was
hoping
to have a WHERE statement that would be temporarly inserted into
underlining
query so that the final query would give the desire output but
then
remove
the WHERE statement afterwords so that a different set of dates could be
evaluated. I know it may seem like the easy way would be to setup a
seperate
underling query but the whole series if very complicated and it seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact situation, but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build another (or
more than one) query to query that.


"David McKnight" <[email protected]>
wrote
in
message
I would like to use a select where statement in a which the
I
have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query
A
WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several
intermediate
queries but I don't think that matters?
 
Getting close!

As i have it written:

Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
qdf.SQL = "SELECT [Query C].* " + "FROM [Query C]" + "WHERE ((([Query
C].Dateof)>=#9/15/**** # And ([Scores-Win Loss].Dateof)<=#12/15/****#));"
Set qdf = Nothing
Set db = Nothing
( This probably gives me enough flexiblity "string", I'll work with the
input boxes later.)

I get a VB run time error # 91.
Object variable or Width block variable not set
--
David McKnight


Rob Oldfield said:
Oops. I missed that Klatuu's suggestion wasn't right. Allen's, however, is
OK...

"SELECT [table A].* FROM [table A] WHERE Month([table A].[DATEOf])=8;" would
give you just August.

With regard to the flexibility, that's a bit of 'how long is a piece of
string' type question. Let's assume that you want the user to be able to
enter two dates and just limit the data to dates between those. The best
way to approach this is to just go to a query window and set it up (using
any two dates). You can then use the View, SQL View command to see the sql
text for that query. That will look something like...

SELECT [Table A].*
FROM [Table A]
WHERE ((([Table A].DateOf)>=#1/1/2005# And ([Table
A].DateOf)<=#1/10/2005#));

so that's the text that you'd need to build, replacing the dummy dates with
the dates that the user has entered. So maybe...

qdf.sql="SELECT [Table A].* "+ _
"FROM [Table A] "+ _
"WHERE ((([Table A].DateOf)>=#"+ _
forms![DateInput]![StartDate]+"# And ([Table A].DateOf)<=#"+ _
forms![DateInput]![EndDate]+"#));"

There's another issue there if you use dd/mm/yyyy format dates. But we'll
worry about that later.




David McKnight said:
When I use this code I get a missing operator error. One thing I don't get
that I'm trying to achieve from the below statement is flexiblity to specify
a month/day combination , say all days between 9/12 & 11/12 for any given
year.
--
David McKnight


Rob Oldfield said:
It will be something like Klatuu posted in your other thread...

qdf.Sql= "SELECT [table A] WHERE Month([DATEOf]) = 8;"



Oops, had a spelling error so "Query C" line is okay. However, having
problems with the next line getting syntax correct.
--
David McKnight


:

Sorry if I'm taking you code too verbatim, but this is how I translated
into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof]. With is
coed I
get a run time error of 3265, Item not found in collection. this is on
lineSet qdf=....
--
David McKnight


:

Yes. That's what I thought you had. The idea is that if your final
query A
is based on another query B which is based on another query C, then
you can
use my example to modify the SQL of C (so limiting it to whatever date
range
you wish), and then use query A.


message
Not really following this reply. Just so you understand better what
I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value
of [a]
for each . I would like some times to have the code avg only by
a set
of
dates (say Aug and Sept) based on a text box. Since my final query
[A]
does
not have a date field, nor could it, to have the corrrect out put.
How can
I
preselect out only Aug and Sept dates based on text box input. I was
hoping
to have a WHERE statement that would be temporarly inserted into
underlining
query so that the final query would give the desire output but then
remove
the WHERE statement afterwords so that a different set of dates
could be
evaluated. I know it may seem like the easy way would be to setup a
seperate
underling query but the whole series if very complicated and it
seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact
situation, but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build
another (or
more than one) query to query that.


in
message
I would like to use a select where statement in a which the I
have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of query A
WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several
intermediate
queries but I don't think that matters?

 
You're getting that because you're not defining what qdf is i.e. you're
missing the set qdf=db.querydefs("QueryName") line. Note though that in
your previous posts we were talking about defining the sql of Query C. If
you're doing that then you can't use Query C as the source of the query.
i.e. you can't base a query on itself. Also, if you just use the ****s in
the sql text then the code will work, but you'll get an error when you
attempt to open the query as it won't recognise it as a date. To pick out
the year, you'd be best off using the year function.


David McKnight said:
Getting close!

As i have it written:

Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
qdf.SQL = "SELECT [Query C].* " + "FROM [Query C]" + "WHERE ((([Query
C].Dateof)>=#9/15/**** # And ([Scores-Win Loss].Dateof)<=#12/15/****#));"
Set qdf = Nothing
Set db = Nothing
( This probably gives me enough flexiblity "string", I'll work with the
input boxes later.)

I get a VB run time error # 91.
Object variable or Width block variable not set
--
David McKnight


Rob Oldfield said:
Oops. I missed that Klatuu's suggestion wasn't right. Allen's, however, is
OK...

"SELECT [table A].* FROM [table A] WHERE Month([table A].[DATEOf])=8;" would
give you just August.

With regard to the flexibility, that's a bit of 'how long is a piece of
string' type question. Let's assume that you want the user to be able to
enter two dates and just limit the data to dates between those. The best
way to approach this is to just go to a query window and set it up (using
any two dates). You can then use the View, SQL View command to see the sql
text for that query. That will look something like...

SELECT [Table A].*
FROM [Table A]
WHERE ((([Table A].DateOf)>=#1/1/2005# And ([Table
A].DateOf)<=#1/10/2005#));

so that's the text that you'd need to build, replacing the dummy dates with
the dates that the user has entered. So maybe...

qdf.sql="SELECT [Table A].* "+ _
"FROM [Table A] "+ _
"WHERE ((([Table A].DateOf)>=#"+ _
forms![DateInput]![StartDate]+"# And ([Table A].DateOf)<=#"+ _
forms![DateInput]![EndDate]+"#));"

There's another issue there if you use dd/mm/yyyy format dates. But we'll
worry about that later.




When I use this code I get a missing operator error. One thing I don't get
that I'm trying to achieve from the below statement is flexiblity to specify
a month/day combination , say all days between 9/12 & 11/12 for any given
year.
--
David McKnight


:

It will be something like Klatuu posted in your other thread...

qdf.Sql= "SELECT [table A] WHERE Month([DATEOf]) = 8;"



Oops, had a spelling error so "Query C" line is okay. However, having
problems with the next line getting syntax correct.
--
David McKnight


:

Sorry if I'm taking you code too verbatim, but this is how I translated
into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof].
With
is
coed I
get a run time error of 3265, Item not found in collection. this
is
on
lineSet qdf=....
--
David McKnight


:

Yes. That's what I thought you had. The idea is that if your final
query A
is based on another query B which is based on another query C, then
you can
use my example to modify the SQL of C (so limiting it to
whatever
date
range
you wish), and then use query A.


"David McKnight" <[email protected]>
wrote
in
message
Not really following this reply. Just so you understand
better
what
I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an
avg
value
of [a]
for each . I would like some times to have the code avg
only
by
a set
of
dates (say Aug and Sept) based on a text box. Since my final query
[A]
does
not have a date field, nor could it, to have the corrrect
out
put.
How can
I
preselect out only Aug and Sept dates based on text box
input. I
was
hoping
to have a WHERE statement that would be temporarly inserted into
underlining
query so that the final query would give the desire output
but
then
remove
the WHERE statement afterwords so that a different set of dates
could be
evaluated. I know it may seem like the easy way would be to setup a
seperate
underling query but the whole series if very complicated and it
seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact
situation, but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then build
another (or
more than one) query to query that.


in
message
I would like to use a select where statement in a which
the
I
have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of
query
A
WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several
intermediate
queries but I don't think that matters?
 
The stars won't work in SQL. You cannot use wildcards in a date. As well,
you're missing a space between the name of the query/table and the keyword
WHERE. Finally, you're referring to a table/query named [Scores-Win Loss],
yet you don't refer to that table/query in the FROM part of your query.

Assuming that the reference to [Scores-Win Loss] should actually be [Query
C], tr


qdf.SQL = "SELECT * FROM [Query C] WHERE " & _
"Format([Dateof], "mmdd") >= '0915' AND " & _
"Format([Dateof], "mmdd") <= '1215'"



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



David McKnight said:
Getting close!

As i have it written:

Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
qdf.SQL = "SELECT [Query C].* " + "FROM [Query C]" + "WHERE ((([Query
C].Dateof)>=#9/15/**** # And ([Scores-Win Loss].Dateof)<=#12/15/****#));"
Set qdf = Nothing
Set db = Nothing
( This probably gives me enough flexiblity "string", I'll work with the
input boxes later.)

I get a VB run time error # 91.
Object variable or Width block variable not set
--
David McKnight


Rob Oldfield said:
Oops. I missed that Klatuu's suggestion wasn't right. Allen's, however,
is
OK...

"SELECT [table A].* FROM [table A] WHERE Month([table A].[DATEOf])=8;"
would
give you just August.

With regard to the flexibility, that's a bit of 'how long is a piece of
string' type question. Let's assume that you want the user to be able to
enter two dates and just limit the data to dates between those. The best
way to approach this is to just go to a query window and set it up (using
any two dates). You can then use the View, SQL View command to see the
sql
text for that query. That will look something like...

SELECT [Table A].*
FROM [Table A]
WHERE ((([Table A].DateOf)>=#1/1/2005# And ([Table
A].DateOf)<=#1/10/2005#));

so that's the text that you'd need to build, replacing the dummy dates
with
the dates that the user has entered. So maybe...

qdf.sql="SELECT [Table A].* "+ _
"FROM [Table A] "+ _
"WHERE ((([Table A].DateOf)>=#"+ _
forms![DateInput]![StartDate]+"# And ([Table A].DateOf)<=#"+ _
forms![DateInput]![EndDate]+"#));"

There's another issue there if you use dd/mm/yyyy format dates. But
we'll
worry about that later.




message
When I use this code I get a missing operator error. One thing I don't
get
that I'm trying to achieve from the below statement is flexiblity to specify
a month/day combination , say all days between 9/12 & 11/12 for any
given
year.
--
David McKnight


:

It will be something like Klatuu posted in your other thread...

qdf.Sql= "SELECT [table A] WHERE Month([DATEOf]) = 8;"



Oops, had a spelling error so "Query C" line is okay. However,
having
problems with the next line getting syntax correct.
--
David McKnight


:

Sorry if I'm taking you code too verbatim, but this is how I translated
into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or 10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof].
With is
coed I
get a run time error of 3265, Item not found in collection. this
is on
lineSet qdf=....
--
David McKnight


:

Yes. That's what I thought you had. The idea is that if your final
query A
is based on another query B which is based on another query C, then
you can
use my example to modify the SQL of C (so limiting it to
whatever date
range
you wish), and then use query A.


"David McKnight" <[email protected]>
wrote in
message
Not really following this reply. Just so you understand
better what
I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg value
of [a]
for each . I would like some times to have the code avg
only by
a set
of
dates (say Aug and Sept) based on a text box. Since my final query
[A]
does
not have a date field, nor could it, to have the corrrect out put.
How can
I
preselect out only Aug and Sept dates based on text box
input. I was
hoping
to have a WHERE statement that would be temporarly inserted
into
underlining
query so that the final query would give the desire output
but then
remove
the WHERE statement afterwords so that a different set of
dates
could be
evaluated. I know it may seem like the easy way would be to setup a
seperate
underling query but the whole series if very complicated and
it
seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact
situation, but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then
build
another (or
more than one) query to query that.


in
message
I would like to use a select where statement in a which
the I
have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of
query A
WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by several
intermediate
queries but I don't think that matters?

 
This gets to what I was trying to do (I had to get rid of the quote marks
"mmdd")

But I still have either a circular reference for query C or I get a vb91
error if I leave the "set qdf=..."line out. What query do I reference? Query
A doesn't have a dateof field.

Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "SELECT * FROM [Query C] WHERE " & "Format([Dateof],mmdd) >=
'0915' AND " & "Format([Dateof], mmdd) <= '1215'"
Set qdf = Nothing
Set db = Nothing
--
David McKnight


Douglas J. Steele said:
The stars won't work in SQL. You cannot use wildcards in a date. As well,
you're missing a space between the name of the query/table and the keyword
WHERE. Finally, you're referring to a table/query named [Scores-Win Loss],
yet you don't refer to that table/query in the FROM part of your query.

Assuming that the reference to [Scores-Win Loss] should actually be [Query
C], tr


qdf.SQL = "SELECT * FROM [Query C] WHERE " & _
"Format([Dateof], "mmdd") >= '0915' AND " & _
"Format([Dateof], "mmdd") <= '1215'"



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



David McKnight said:
Getting close!

As i have it written:

Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
qdf.SQL = "SELECT [Query C].* " + "FROM [Query C]" + "WHERE ((([Query
C].Dateof)>=#9/15/**** # And ([Scores-Win Loss].Dateof)<=#12/15/****#));"
Set qdf = Nothing
Set db = Nothing
( This probably gives me enough flexiblity "string", I'll work with the
input boxes later.)

I get a VB run time error # 91.
Object variable or Width block variable not set
--
David McKnight


Rob Oldfield said:
Oops. I missed that Klatuu's suggestion wasn't right. Allen's, however,
is
OK...

"SELECT [table A].* FROM [table A] WHERE Month([table A].[DATEOf])=8;"
would
give you just August.

With regard to the flexibility, that's a bit of 'how long is a piece of
string' type question. Let's assume that you want the user to be able to
enter two dates and just limit the data to dates between those. The best
way to approach this is to just go to a query window and set it up (using
any two dates). You can then use the View, SQL View command to see the
sql
text for that query. That will look something like...

SELECT [Table A].*
FROM [Table A]
WHERE ((([Table A].DateOf)>=#1/1/2005# And ([Table
A].DateOf)<=#1/10/2005#));

so that's the text that you'd need to build, replacing the dummy dates
with
the dates that the user has entered. So maybe...

qdf.sql="SELECT [Table A].* "+ _
"FROM [Table A] "+ _
"WHERE ((([Table A].DateOf)>=#"+ _
forms![DateInput]![StartDate]+"# And ([Table A].DateOf)<=#"+ _
forms![DateInput]![EndDate]+"#));"

There's another issue there if you use dd/mm/yyyy format dates. But
we'll
worry about that later.




message
When I use this code I get a missing operator error. One thing I don't
get
that I'm trying to achieve from the below statement is flexiblity to
specify
a month/day combination , say all days between 9/12 & 11/12 for any
given
year.
--
David McKnight


:

It will be something like Klatuu posted in your other thread...

qdf.Sql= "SELECT [table A] WHERE Month([DATEOf]) = 8;"



message
Oops, had a spelling error so "Query C" line is okay. However,
having
problems with the next line getting syntax correct.
--
David McKnight


:

Sorry if I'm taking you code too verbatim, but this is how I
translated
into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or
10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof].
With
is
coed I
get a run time error of 3265, Item not found in collection. this
is
on
lineSet qdf=....
--
David McKnight


:

Yes. That's what I thought you had. The idea is that if your
final
query A
is based on another query B which is based on another query C,
then
you can
use my example to modify the SQL of C (so limiting it to
whatever
date
range
you wish), and then use query A.


"David McKnight" <[email protected]>
wrote
in
message
Not really following this reply. Just so you understand
better
what
I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg
value
of [a]
for each . I would like some times to have the code avg
only
by
a set
of
dates (say Aug and Sept) based on a text box. Since my final
query
[A]
does
not have a date field, nor could it, to have the corrrect out
put.
How can
I
preselect out only Aug and Sept dates based on text box
input. I
was
hoping
to have a WHERE statement that would be temporarly inserted
into
underlining
query so that the final query would give the desire output
but
then
remove
the WHERE statement afterwords so that a different set of
dates
could be
evaluated. I know it may seem like the easy way would be to
setup a
seperate
underling query but the whole series if very complicated and
it
seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact
situation, but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then
build
another (or
more than one) query to query that.


"David McKnight" <[email protected]>
wrote
in
message
I would like to use a select where statement in a which
the
I
have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of
query
A
WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by
several
intermediate
queries but I don't think that matters?

 
What you are doing is setting the SQL for Query C. That can't pull data out
of Query C as, as the error suggests, it's pulling data out of Query C and
going round in circles.

If you set the series of queries just using static dates, which one contains
the date conditions? That's the one that you need on the "set qdf" line.


David McKnight said:
This gets to what I was trying to do (I had to get rid of the quote marks
"mmdd")

But I still have either a circular reference for query C or I get a vb91
error if I leave the "set qdf=..."line out. What query do I reference? Query
A doesn't have a dateof field.

Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "SELECT * FROM [Query C] WHERE " & "Format([Dateof],mmdd) >=
'0915' AND " & "Format([Dateof], mmdd) <= '1215'"
Set qdf = Nothing
Set db = Nothing
--
David McKnight


Douglas J. Steele said:
The stars won't work in SQL. You cannot use wildcards in a date. As well,
you're missing a space between the name of the query/table and the keyword
WHERE. Finally, you're referring to a table/query named [Scores-Win Loss],
yet you don't refer to that table/query in the FROM part of your query.

Assuming that the reference to [Scores-Win Loss] should actually be [Query
C], tr


qdf.SQL = "SELECT * FROM [Query C] WHERE " & _
"Format([Dateof], "mmdd") >= '0915' AND " & _
"Format([Dateof], "mmdd") <= '1215'"



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Getting close!

As i have it written:

Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
qdf.SQL = "SELECT [Query C].* " + "FROM [Query C]" + "WHERE ((([Query
C].Dateof)>=#9/15/**** # And ([Scores-Win Loss].Dateof)<=#12/15/****#));"
Set qdf = Nothing
Set db = Nothing
( This probably gives me enough flexiblity "string", I'll work with the
input boxes later.)

I get a VB run time error # 91.
Object variable or Width block variable not set
--
David McKnight


:

Oops. I missed that Klatuu's suggestion wasn't right. Allen's, however,
is
OK...

"SELECT [table A].* FROM [table A] WHERE Month([table A].[DATEOf])=8;"
would
give you just August.

With regard to the flexibility, that's a bit of 'how long is a piece of
string' type question. Let's assume that you want the user to be able to
enter two dates and just limit the data to dates between those. The best
way to approach this is to just go to a query window and set it up (using
any two dates). You can then use the View, SQL View command to see the
sql
text for that query. That will look something like...

SELECT [Table A].*
FROM [Table A]
WHERE ((([Table A].DateOf)>=#1/1/2005# And ([Table
A].DateOf)<=#1/10/2005#));

so that's the text that you'd need to build, replacing the dummy dates
with
the dates that the user has entered. So maybe...

qdf.sql="SELECT [Table A].* "+ _
"FROM [Table A] "+ _
"WHERE ((([Table A].DateOf)>=#"+ _
forms![DateInput]![StartDate]+"# And ([Table A].DateOf)<=#"+ _
forms![DateInput]![EndDate]+"#));"

There's another issue there if you use dd/mm/yyyy format dates. But
we'll
worry about that later.




message
When I use this code I get a missing operator error. One thing I don't
get
that I'm trying to achieve from the below statement is flexiblity to
specify
a month/day combination , say all days between 9/12 & 11/12 for any
given
year.
--
David McKnight


:

It will be something like Klatuu posted in your other thread...

qdf.Sql= "SELECT [table A] WHERE Month([DATEOf]) = 8;"



message
Oops, had a spelling error so "Query C" line is okay. However,
having
problems with the next line getting syntax correct.
--
David McKnight


:

Sorry if I'm taking you code too verbatim, but this is how I
translated
into
what I'm trying to do.


Dim db As Database
Set db = CurrentDb
Dim qdf As QueryDef
Set qdf = db.QueryDefs("Query C")
qdf.SQL = "select * [Dateof]= 8/*/****, or 9/*/****, Or
10/1/****"
Set qdf = Nothing
Set db = Nothing

Query C being the orginal query with a field called [Dateof].
With
is
coed I
get a run time error of 3265, Item not found in collection. this
is
on
lineSet qdf=....
--
David McKnight


:

Yes. That's what I thought you had. The idea is that if your
final
query A
is based on another query B which is based on another query C,
then
you can
use my example to modify the SQL of C (so limiting it to
whatever
date
range
you wish), and then use query A.


"David McKnight" <[email protected]>
wrote
in
message
Not really following this reply. Just so you understand
better
what
I'm
trying to do .. more info.
I have a rather complex series of queries that gets me an avg
value
of [a]
for each . I would like some times to have the code avg
only
by
a set
of
dates (say Aug and Sept) based on a text box. Since my final
query
[A]
does
not have a date field, nor could it, to have the corrrect out
put.
How can
I
preselect out only Aug and Sept dates based on text box
input. I
was
hoping
to have a WHERE statement that would be temporarly inserted
into
underlining
query so that the final query would give the desire output
but
then
remove
the WHERE statement afterwords so that a different set of
dates
could be
evaluated. I know it may seem like the easy way would be to
setup a
seperate
underling query but the whole series if very complicated and
it
seems like
code could do this.
David McKnight


:

There might be a better solution depending on your exact
situation, but
you
can set the SQL of a query by something like...

dim db as database
set db=currentdb
dim qdf as querydef
set qdf = db.querydefs("QueryName")
qdf.sql = "select * from whatever where field=3"
set qdf=nothing
set db=nothing

Just use that to pick out where month=8 or 9, and then
build
another (or
more than one) query to query that.


"David McKnight"
wrote
in
message
I would like to use a select where statement in a which
the
I
have a
series
of queries

ie,

Table A [date] [value a] [value b]

Query A [Table A]![Avg OF value a],[Table A]![value b]

With code in my form I would like to select results of
query
A
WHERE
[date]
is months equal to 8 & 9.

In my real code Table A and Query A are seperated by
several
intermediate
queries but I don't think that matters?
 
Back
Top