473,322 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,322 software developers and data experts.

Running SQL query for each record in table

Warning:: I am very new to programming, having never had to use VBA before, traditionally i am a SQL/Crystal Reports writer... with that in mind:

I am currently writing ar eport to extract data from a table into seperate excel worksheets and workbooks.

In the simpliest case the table_one has three fields, Account, Region, status.

each region requires it's own Excel file, and each status it's own worksheet. I have managed to perform the simple tasks of exporting the work data from access by manually setting up a code for each of the variable in region and status, but these are constantly changing.

How would i write a query that would extract this data for every varying region and status?


I have been looking around and managed to get to
Expand|Select|Wrap|Line Numbers
  1. Public Sub search_query()
  2.  
  3. Dim results As String
  4. Dim objXLSheet As Object
  5. Dim myrecordset As New ADODB.Recordset
  6.  
  7. myrecordset.Open "[table_one]", CurrentProject.Connection
  8.  
  9. Dim myfield As Object
  10.  
  11. For Each myfield In myrecordset.Fields
  12.  
  13. Set objXLSheet = objxlapp.worksheets("2")
  14. Else
  15. Next
  16. objXLSheet.Range("a2").CopyFromRecordset myrecordset
  17.  
  18. End Sub
  19.  
However this produces the first row from each column, maybe i need more books!
Jul 10 '07 #1
0 1596

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

Similar topics

8
by: Phoenix | last post by:
Here's a challenge that is killing me: I've got 2 web servers and a SQL Server and about 5,000 'users' who stay connected to the site all day. I have a page that is supposed to be 'real-time',...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
16
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
5
by: Sean Byrne | last post by:
We have a Microsoft Access 2000 database consisting of 20 tables covering 20 different events. In each table, there are 3 Team members, a date of the event and several unique fields for the event,...
2
by: lgo | last post by:
I have read several variations of this topic posted on this news group. However I was not able to find the answer for my problem. I am trying to build code (see below) to update a large single...
1
by: ????? | last post by:
I have a query which shows the following fields and orders by every one in turn from left to right in ascending order. The fields are DATE, , WORK, *, DESCRIPTION and . How can I get a running...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
2
by: Venk | last post by:
hi all, I saw one reply to arun on the subject "Dynamic Query in Ms-Access" by one Mr Rick I found it very useful. Now to extend this solution forward I have the following situation. I...
3
by: Phil Stanton | last post by:
I have a number of queries which use code for the output of 1 or more fields. For example Address:GetAddress(AddressID, True, 60) Address ID Points to an Address in a table - Address Line1, Line...
9
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.