473,513 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11256
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
8370
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 logindisabled=FALSE Instead of parsing this text and assigning the values, I was wondering
25
4306
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 them, but the assign operator is always forcing them to "type cast" or coerce the result when they do a simple assign for the purpose of setting the...
2
2470
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 number entered in the form, and then include the database reading into it. THE PROBLEM: <%
2
26001
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
534
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: Dim anInteger As Integer Dim strSelect As String strSelect = "SELECT MAX(tblTable.autonumberColumn) From tblTable;"
6
2249
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 = ds.Tables("mmsSpecRecord").Rows(0)("Q1") txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2") ..... txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10") ------code ------- Dim...
3
18625
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 date fields that may or maynot have date values, if no date values exists in the source field, the value is null. but when I pass a record from the...
7
18140
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 query (select user from dual) to the variable. It's possible? i know that it's possible to do by this statement "select user into o_user from...
2
7198
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 query string which passes the SID from this page. <a href="loginthanks.php?<?php echo htmlspecialchars(SID); ?>" > now how can i send the login...
0
7269
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7559
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7542
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.