By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,696 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,696 IT Pros & Developers. It's quick & easy.

Get values from query

P: n/a
I run a query in VB that calculates an average and a count. Again in code I
want to grab those 2 values from that query without having to write them
first to a table and read the values from that table. How do I go about
this?
Thanks,
john
Jul 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Jul 12, 5:45 pm, "John" <j...@hn.comwrote:
I run a query in VB that calculates an average and a count. Again in code I
want to grab those 2 values from that query without having to write them
first to a table and read the values from that table. How do I go about
this?
Thanks,
john
You read a query the same way you would read a table

'Here you would load the query parameters if any
set myRecordset = MyBase.OpenRecordset("MyQueryName")

debug.print myRecordset("MyFirstFieldName") 'Average
debug.print myRecordset("MySecondFieldName") 'Count

Regards
C.

Jul 12 '07 #2

P: n/a
Thanks. The one thing I don't get about this approach is:
"MyQueryName" in my case is actually an sql-string and not a saved query. So
I don't have a query name. Is there a way to perform the action you mention
where MyQueryName is in fact the sql-string? I don't want to save the query.
john

"Chris L." <di******@uol.com.arschreef in bericht
news:11**********************@o61g2000hsh.googlegr oups.com...
On Jul 12, 5:45 pm, "John" <j...@hn.comwrote:
>I run a query in VB that calculates an average and a count. Again in code
I
want to grab those 2 values from that query without having to write them
first to a table and read the values from that table. How do I go about
this?
Thanks,
john

You read a query the same way you would read a table

'Here you would load the query parameters if any
set myRecordset = MyBase.OpenRecordset("MyQueryName")

debug.print myRecordset("MyFirstFieldName") 'Average
debug.print myRecordset("MySecondFieldName") 'Count

Regards
C.

Jul 12 '07 #3

P: n/a
John: You just put the SQL-String in the OpenRecordset command, like
this:

set myRecordset = MyBase.OpenRecordset("Select count(*) from MyTable")

Regards

On Jul 12, 6:22 pm, "John" <j...@hn.comwrote:
Thanks. The one thing I don't get about this approach is:
"MyQueryName" in my case is actually an sql-string and not a saved query. So
I don't have a query name. Is there a way to perform the action you mention
where MyQueryName is in fact the sql-string? I don't want to save the query.
john

"Chris L." <diver...@uol.com.arschreef in berichtnews:11**********************@o61g2000hsh.g ooglegroups.com...
On Jul 12, 5:45 pm, "John" <j...@hn.comwrote:
I run a query in VB that calculates an average and a count. Again in code
I
want to grab those 2 values from that query without having to write them
first to a table and read the values from that table. How do I go about
this?
Thanks,
john
You read a query the same way you would read a table
'Here you would load the query parameters if any
set myRecordset = MyBase.OpenRecordset("MyQueryName")
debug.print myRecordset("MyFirstFieldName") 'Average
debug.print myRecordset("MySecondFieldName") 'Count
Regards
C.- Hide quoted text -

- Show quoted text -

Jul 13 '07 #4

P: n/a
I'm not very familiar with recordsets but now I got it to work.
Thanks!
john

"Chris L." <di******@uol.com.arschreef in bericht
news:11*********************@r34g2000hsd.googlegro ups.com...
John: You just put the SQL-String in the OpenRecordset command, like
this:

set myRecordset = MyBase.OpenRecordset("Select count(*) from MyTable")

Regards

On Jul 12, 6:22 pm, "John" <j...@hn.comwrote:
>Thanks. The one thing I don't get about this approach is:
"MyQueryName" in my case is actually an sql-string and not a saved query.
So
I don't have a query name. Is there a way to perform the action you
mention
where MyQueryName is in fact the sql-string? I don't want to save the
query.
john

"Chris L." <diver...@uol.com.arschreef in
berichtnews:11**********************@o61g2000hsh. googlegroups.com...
On Jul 12, 5:45 pm, "John" <j...@hn.comwrote:
I run a query in VB that calculates an average and a count. Again in
code
I
want to grab those 2 values from that query without having to write
them
first to a table and read the values from that table. How do I go
about
this?
Thanks,
john
You read a query the same way you would read a table
'Here you would load the query parameters if any
set myRecordset = MyBase.OpenRecordset("MyQueryName")
debug.print myRecordset("MyFirstFieldName") 'Average
debug.print myRecordset("MySecondFieldName") 'Count
Regards
C.- Hide quoted text -

- Show quoted text -


Jul 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.