473,385 Members | 1,379 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,385 software developers and data experts.

given an sql select query, how to get the data

I feel quite dumb having to ask this, but I cannot seem to find this in
the Microsft documentation pages.

In Access 2000, I create a string containing the sql query:

Dim MaxSerial As Integer
Dim Longyear As Integer
Longyear = year(Date)

Query = "select max(serialnumber) from participants " _
+ "where startyear = " + Str(Longyear)

I would like to have the result of this query in a basic variable.

MaxSerial = ????

I do not, in principle, want to create a form or window showing a table
of records, I just want to get a number in the variable, or NULL if
there is no row in 'participants' having non-null 'startyear'.

Thanks,
Enrique

Nov 13 '05 #1
1 1308
On 18 May 2005 04:22:47 -0700, "en***@online.no" <en***@online.no>
wrote:

Option 1: Use the DMax function. 1-line solution, but perhaps not very
fast for large (> 1000 rows) data sets.

Option 2: Use VBA code with DAO to capture the results in a recordset,
then read the value into your variable:
dim db as dao.database
dim rs as dao.recordset
set db = currentdb()
set rs = db.OpenRecordset(Query, dbOpenSnapshot)
MaxSerial = rs(0)
rs.close ' etc.

Option 3: Use a stored query, with a parameter.
The query:
select max(serialnumber) from participants where startyear =
[parStartYear]
The code:
dim db as dao.database
dim rs as dao.recordset
dim qd as dao.querydefs
set db = currentdb()
set qd = db.querydefs("MyQuery")
qd!parStartYear = Longyear
set rs = qd.OpenRecordset(dbOpenSnapshot)
MaxSerial = rs(0)
rs.close ' etc.

-Tom.

I feel quite dumb having to ask this, but I cannot seem to find this in
the Microsft documentation pages.

In Access 2000, I create a string containing the sql query:

Dim MaxSerial As Integer
Dim Longyear As Integer
Longyear = year(Date)

Query = "select max(serialnumber) from participants " _
+ "where startyear = " + Str(Longyear)

I would like to have the result of this query in a basic variable.

MaxSerial = ????

I do not, in principle, want to create a form or window showing a table
of records, I just want to get a number in the variable, or NULL if
there is no row in 'participants' having non-null 'startyear'.

Thanks,
Enrique


Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jsfromynr | last post by:
Hi all, I have two tables CREATE TABLE ( NOT NULL , NULL , -- CURRENT DESIGNATION OF EMPLOYEE NOT NULL ) ON GO
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
4
by: m_houllier | last post by:
STUDENT TABLE StudentReference Student Name etc ATTENDANCE TABLE AttendanceID CourseID StudentReference
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
22
by: Rickster66 | last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back" I'm sorry for the late response. I've been gathering up information and carefully with as much...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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:
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.