473,395 Members | 2,713 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,395 software developers and data experts.

vba to loop thru access table and query each record

Hello,

I am trying to do something that sounds simple, but it seems impossible to me after trying for many hours.

I want to iterate thru a table, grab the ID field, and run a series of queries based on the ID.

Desired steps:
Grab the ID from record 1
Run query 1
run an add-in to do percentile analysis (this works just fine)
insert into the "results" table (prior versions of this table can be deleted)


Grab the ID from record 2
run query 1
run an add-in to do percentile analysis
append to the results table

repeat...

So far, I have failed miserably, can get it to run thru the IDs table and display the contents of each record. I even got it to run the query one time, but am stuck. Any help is gratefully appreciated.

[code]

Private Sub showTableData()

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("ids") 'ids is a unique ID of all respondents

Dim sSQL As String
Dim sValue As String


Do While Not rs.EOF
' Debug.Print (rs!company) 'myField is a field name in table myTable

sValue = rs("id")
MsgBox sValue
sSQL = "select * from realcd where id=" & sValue
MsgBox sSQL


Dim qdf As QueryDef
Set qdf = CurrentDb.CreateQueryDef("tempquery", sSQL)
db.QueryDefs.Refresh


DoCmd.OpenQuery ("tempquery")



rs.MoveNext 'press Ctrl+G to see debuG window beneath
Loop

' MsgBox ("End of Table")

End Sub
{/CODE]
Sep 11 '17 #1
0 1760

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

Similar topics

1
by: Eric Martin | last post by:
Hello, Does anyone know of a way to loop thru a SQL table using code in a stored procedure? I need to go thru each record in a small table and build a string using values from the fields...
3
by: Phil Rutter | last post by:
Hello All, I have about 700 word documents that have 2 tables one is static 4 colums x 5 rows the other is 5 colums x rows ranging from 2 to 100 what i wolud like to do is open the word doc....
2
by: SenseForAll | last post by:
First please note I am a novice at VBA and not even that experienced with DAO/ADO and MS-SQL. Any assistance is appreciated. That said... I have an application written in Access w/ VBA. I need to...
0
by: JDMils | last post by:
I am having trouble finding the AutoNumber field of my database with this code. The code is used to replicate a specific table, reproducing all columns including indexes and Primary Keys (there is...
2
by: jalmar | last post by:
Hello....I'm back again with the same question. I still haven't been able to figure out why my query isn't working. I am linking a table to an Excel spreadsheet, that part is fine, it is even...
5
by: Lefke123 | last post by:
hello, does anyone know how to write certain information from a table / query using VB into a new excel sheet for example; i press a button and a printable excel file is made with the name...
10
by: Ben Cherry | last post by:
Hi I have created a tablein acess 07 with three fields; admno, name, and Mark/100. My problem is that i need to have a field with position of this students based on the marks i.e the one with highest...
7
by: Nilou | last post by:
Hi experts, I'm very new to access and VBA, I am Looking to find a way to join two tables. To join these two table, I need to loop through my second table and for each row exist in second table I...
1
by: bdavis6290 | last post by:
I have 2 tables' tblRHM and tblRHM1. tblRHM has suploc, penloc, and RHM. tblRHM1 has RHM1, suploc, penloc, fname, lname, mname, dob, address, b1, b2, b3, and uniqueID . I also have a template I would...
3
by: Ms2BSwagg | last post by:
HI, I would like to show the 1st 5 characters of Customers First and Last Name combined into one field. Eg John Snow = SnowJ Thanks in advance.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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.