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

How to save result from query into a variable...

I'm trying to save a result data into a variable but i don't have a clue on how to do it... can anyone help me with this?..

i'm pretty sure that this is wrong but this is what i'm trying to do

Expand|Select|Wrap|Line Numbers
  1.  Dim product as String
  2.  
  3. product = DoCmd.RUNSQL = "SELECT product_name FROM product" 
let's just assume that the query returns only a single row... and i'm using ms access 2007 by the way... hope somebody can help me..
Oct 10 '10 #1
1 27933
dsatino
393 256MB
Expand|Select|Wrap|Line Numbers
  1. Dim rst as recordset
  2. Dim product as string
  3. Dim db as database
  4.  
  5. Set db = currentdb
  6.  
  7. Set rst = db.openrecordset("SELECT product_name FROM product")
  8.  
  9. With rst
  10.    .movefirst
  11.    product = .fields(0)
  12. End with
  13.  
  14. set rst = nothing
  15. set db = nothing
  16.  
This will only capture the variable for use within this sub though. If you need to use it elsewhere you'll need to pass it to the other procedure or simply declare the variable as Global outside of this procedure.
Oct 11 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Trillium | last post by:
I am trying to query a SQL Server database, retrieve the results as XML, and save them to a file. I was trying to use the SqlXmlCommand, SqlXmlCommandType.XPath and an xsd to query the database,...
1
by: Randy K | last post by:
I have a table with some 35000 records and I need some help sorting it out. The goal is to get counts of failures modes oraganized by serial number. the table is set up roughly like this. s/n ...
4
by: Jim via DotNetMonster.com | last post by:
Hi, How can I assign the result of a function to a variable. I need to get the result so that I can query the database again. What I'm trying is:...
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 ...
1
by: blue875 | last post by:
SELECT Service.Name As AtlasProductName, IIf(Service.Name Like "1004*", "1004/URAR", IIf(Service.Name Like "2055E CompPhots&Land", "2055 Ext w/Comp Pics", IIf(Service.Name Like "2055I...
5
by: James Mitchelhill | last post by:
Sorry for the clunky subject line - I have a feeling that not knowing the proper terms for this is part of my problem. I'm trying to write a class that analyses some data. I only want it to do...
2
by: awu | last post by:
All: I have a query that has 5 fields and around 15500 records. I need to save it to a excel file that has two sheets. First sheet saves all the 15500 records. Second sheet saves around 7500...
2
by: Merio | last post by:
I want to save a query result to a new table. Is this possible using sql commands? Like: Select Col1, Col2, Col7 from tbl1 Order by Col1 - Save it to tbl2 using the same column headers generated...
6
by: Busbait | last post by:
I need to know how can I store SQL result into variable, I have used the below code but it dose not work. Is there an easier way to do this? ...
0
by: FLANDERS | last post by:
Hi all, Is it possible to declare a SQL type of result set or similar? I want to do use the IN predicate like you can in a non-procedural SQL like this: UPDATE TABLE1 SET COL1 = 123 WHERE COL2 IN...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.