473,378 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Get values from query

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
4 8731
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wilder | last post by:
I'm trying to update a field in one table with the minimum values of the field in another table. The two tables are linked via a common field. I want to populate a date field in one table with...
3
by: MX1 | last post by:
I'm ready to pull the hair out of my head. I have a query with a couple of parameters that I want to get from combo boxes on a form. One parameter is a date with a dynamically calculated year and...
2
by: Todd D. Levy | last post by:
I have a table of Country names & Country codes in alphabetical order. This is a lookup table that a number of other tables use to populate the Country field via a drop down Combo Box on the...
3
by: JOEP | last post by:
What do I need to do to allow an append query to post null values to records in a field of the destination table? Basically I want to allow records with null values to post to the table. The append...
19
by: bdt513 | last post by:
I am trying to extract the values from a query using VBA. Specifically, I want to concatenate all the values of the "rosEmail" field from query "qselRosterEmailList" into one string (strEmails). I...
2
by: Keith | last post by:
Good Afternoon, New to .Net. I am trying to pass date/time values to a MS Access query depending on what value is selected from a dropdown list box (January, February, etc). I have declared...
3
by: robboll | last post by:
I am building an ASP.NET data entry form and when I change the values per the dropdowns and click "save", the old values remain. Are there any suggestions on how to update the variables to the...
4
by: Juan Jose Costello Levien | last post by:
Hello, I am writing my first trigger in C for PostgreSQL. It compiles Ok, and added it to the database using CREATE TRIGGER. But when I try to fire it, psql simply says 'The connection was lost"....
2
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
7
by: sparks | last post by:
I am working on a database that has a lot of calculated values on the forms. These were never put into the tables. But were tied to unbound fields on the forms. Now 8000 records later they want...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.