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

Assign value to variable from query

How would I assign the MAX(value) in a tablecolumn to an Integer
variable, or put another way, assign any value from a table record to a
variable?

I am trying to achieve something like this:

Dim anInteger As Integer
Dim strSelect As String
strSelect = "SELECT MAX(tblTable.autonumberColumn) From tblTable;"

anInteger = CurrentDb.Execute(strSelect) 'or
anInteger = DoCmd.RunSQL(strSelect)

Neither DoCmd.RunSQL or CurrentDb.Execute lets me do this. I must be
missing something basic and essential since I get an easy understandable
error message stating: "compile error, expected function or variable"
and that I have not found any information where someone is trying to do
something similar.

I am not completely new to programming and databases, and I do belive I
remember doing something very similar with a window-application using
VB.NET and Access, but in Access 2003 VBA I am stuck.

I would be grateful if someone would point me in the right direction
(and sorry if this is a stupid question, I will not be surprised if it is)
Jan 23 '06 #1
1 11249
Dim AnIntegerMayNotBeBigEnough as Long
' JET's INTEGER = VBA'S Long
AnIntegerMayNotBeBigEnough = CurrentDb.OpenRecordset("SELECT Max(ID)
FROM Customers").Collect(0)

Jan 23 '06 #2

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

Similar topics

9
by: Mike | last post by:
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z...
25
by: Rim | last post by:
Hi, I have been thinking about how to overload the assign operation '='. In many cases, I wanted to provide users of my packages a natural interface to the extended built-in types I created for...
2
by: news.cablevision.qc.ca | last post by:
Hi! I want, using a form, enter a number and then, read that number of records in a database and store information in variables. The only way I see to do this is to do a FOR...NEXT to the...
2
by: Matt | last post by:
If I assign Java variable a to javascript variable x, it is fine. <% int a = 10; %> var x = <%= a %>; alert(x); But if I do the other way around, then it has 500 error. any ideas??
0
by: Roger Oshaug | last post by:
How would I assign the MAX(value) in a tablecolumn to an Integer variable, or put another way, assign any value from a table record to a variable? I am trying to achieve something like this: ...
6
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
3
by: Liam Mac | last post by:
Hi All, Can anyone direct me or provide advice on how I can assign a null value to a date variable in vb.net. Basically what I'm doing is that I'm looping through a recordset where I have three...
7
by: trakal | last post by:
Hello everybody, i create a stored producedure in Oracle that will get the user name who connect to Oracle database. For exemple, i declare a variable "o_user" and i want to assign the value of the...
2
by: rahullko05 | last post by:
i am stuck in the problem, where after user logs in successfuly, i take him to the login thanks page. now on that page i need to retain the login name. I am not sure how to this. i have written a...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.