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

export query results to multiple text files

Hello,

I have data in an Access table that I would like to export to multiple
HTML tables. I would like to split the data in the Access table
(about 92,000 records) into multiple HTML tables/files to reduce
download time and bandwidth usage on my web server. That way, the
user can select a particular page to download instead of downloading a
page with all of the records.

I would like to set a limit of only 500 records per file.

For example, I would like to be able to read from an Access Query,
'qryA'. This query selects all records whose part number starts with
"A".

The pseudo-code for the routine that I would like to run is as
follows:

// Variables
RecordCount = 1
PageCount = 1
Buffer = some kind of temp space
Outfile = qryA-(PageCount).shtml
// (The filename for the first pass would be qryA-1.shtml)

Read all records from qryA into Buffer
while not EOF (Buffer)
{
----->write to Outfile "<table>"
-----> while RecordCount <= 500 {
-------->read next line from 'Buffer'
-------->write to Outfile "<tr><td>Buffer.fieldA</td></tr>"
-------->write to Outfile "<tr><td>Buffer.fieldB</td></tr>"
-------->write to Outfile "<tr><td>Buffer.fieldC</td></tr>"
-------->write to Outfile "<br>"
-------->RecordCount = RecordCount + 1
--------> }
------> write to Outfile "</table>"
------> Close Outfile
------> RecordCount = 1
------> PageCount = PageCount + 1
}

// If the dataset had 1400 records I should end up with 3 files:
qryA-1.shtml (500 records)
qryA-2.shtml (500 records)
qryA-3.shtml (400 records)

This seems to be a fairly simple algorithm, but I have not coded in
quite some time. I would like to do this within Access 97 VBA if
possible. Any help would be appreciated

Thank you very much in advance.
Nov 12 '05 #1
1 6534
In article <95*************************@posting.google.com> ,
ad***@mentorelectronics.com (Charlie) writes:
Hello,

I have data in an Access table that I would like to export to multiple
HTML tables. I would like to split the data in the Access table
(about 92,000 records) into multiple HTML tables/files to reduce
download time and bandwidth usage on my web server. That way, the
user can select a particular page to download instead of downloading a
page with all of the records.

I would like to set a limit of only 500 records per file.

For example, I would like to be able to read from an Access Query,
'qryA'. This query selects all records whose part number starts with
"A".

The pseudo-code for the routine that I would like to run is as
follows:

// Variables
RecordCount = 1
PageCount = 1
Buffer = some kind of temp space
Outfile = qryA-(PageCount).shtml
// (The filename for the first pass would be qryA-1.shtml)

Read all records from qryA into Buffer
while not EOF (Buffer)
{
----->write to Outfile "<table>"
-----> while RecordCount <= 500 {
-------->read next line from 'Buffer'
-------->write to Outfile "<tr><td>Buffer.fieldA</td></tr>"
-------->write to Outfile "<tr><td>Buffer.fieldB</td></tr>"
-------->write to Outfile "<tr><td>Buffer.fieldC</td></tr>"
-------->write to Outfile "
"
-------->RecordCount = RecordCount + 1
--------> }
------> write to Outfile "</table>"
------> Close Outfile
------> RecordCount = 1
------> PageCount = PageCount + 1
}

// If the dataset had 1400 records I should end up with 3 files:
qryA-1.shtml (500 records)
qryA-2.shtml (500 records)
qryA-3.shtml (400 records)

This seems to be a fairly simple algorithm, but I have not coded in
quite some time. I would like to do this within Access 97 VBA if
possible. Any help would be appreciated

Thank you very much in advance.


Charlie

This code should get you going in the right direction:
Sub sCreateStaticHTMLFiles()
On Error GoTo E_Handle
Dim db As Database ' Database object
Dim rs As Recordset ' Recordset object
Dim strHTMLFile As String ' Path and name of the HTML file to be
written to
Dim strSQL As String ' SQL String
Dim intFile As Integer ' File number being dealt with
Dim intCountFiles As Integer ' Number of files to be created
Dim intHTMLFile As Integer ' File allocation number
Dim strOutput As String ' Data to be written to the file
Set db = DBEngine(0)(0)
' Get the number of files to be created (rounding up)
intCountFiles = -Int(-DCount("OrderID", "Orders") / 100)
' Deal with the first 500 records
strSQL = "SELECT TOP 500 * FROM Orders " _
& " ORDER BY OrderID ASC;"
Set rs = db.OpenRecordset(strSQL)
If Not (rs.BOF And rs.EOF) Then
strHTMLFile = "D:\Test0.htm"
intHTMLFile = FreeFile
Open strHTMLFile For Output As intHTMLFile
Print #intHTMLFile, "<html><body><table>"
Do
strOutput = "<tr><td>" & rs!OrderID & "</td><td>" & rs!CustomerID &
"</td></tr>"
Print #intHTMLFile, strOutput
rs.MoveNext
Loop Until rs.EOF
Print #intHTMLFile, "</table></body></html>"
Close #intHTMLFile
End If
rs.Close
' Now deal with subsequent batches of 500 records
For intFile = 1 To intCountFiles
strSQL = "SELECT TOP 500 * FROM Orders " _
& " WHERE OrderID NOT IN " _
& " (SELECT TOP " & 100 * intFile & " OrderID FROM Orders ORDER BY
OrderID ASC) " _
& " ORDER BY OrderID ASC;"
Set rs = db.OpenRecordset(strSQL)
If Not (rs.BOF And rs.EOF) Then
strHTMLFile = "D:\Test" & intFile & ".htm"
intHTMLFile = FreeFile
Open strHTMLFile For Output As intHTMLFile
Print #intHTMLFile, "<html><body><table>"
Do
strOutput = "<tr><td>" & rs!OrderID & "</td><td>" &
rs!CustomerID & "</td></tr>"
Print #intHTMLFile, strOutput
rs.MoveNext
Loop Until rs.EOF
Print #intHTMLFile, "</table></body></html>"
Close #intHTMLFile
End If
rs.Close
Next intFile
sExit:
On Error Resume Next
rs.Close
Set rs = Nothing
Set db = Nothing
Reset
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
--

Jon

www.applecore99.com - Access Tips and Tricks

Nov 12 '05 #2

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

Similar topics

0
by: Rob | last post by:
I doubt this is the best way to do it, but what I came up with was to hide the XML in an HTML Comment then edit the file deleting the HTML stuff and keep the XML results. If anyone has a better...
2
by: Chris Murphy via DotNetMonster.com | last post by:
Hey all, just wondering if anyone can point me in the right direction. I'm developing a solution that allows a user to store multiple text-based content (like code snippets, notes, documents etc.)...
5
by: Buddhist[CHinA] | last post by:
The text files are not only the .txt files, but also all ascii files. Thx.
2
by: ManningFan | last post by:
I'm running through a database in a loop, and each time the loop finishes I would like to export the values of some variables to new text files. In reality it's more complex than this, but this is...
3
emaghero
by: emaghero | last post by:
Hello all, I want to open multiple txt files with similar names in C++ I have attempted this with the following code //Create as many txt files as there are valid propagation constants...
6
by: borthouth | last post by:
Hi, I have just started using Python and I am slowly getting into it. I wanted to make a little script to merge all files in a directory into one. All of these files will be text files. I...
3
by: Chris McFarling | last post by:
What's the most efficient method to export the result set of a SQL query to a text file using ASP.NET? There could potentially be a few thousand rows.
2
by: as001 | last post by:
Hi, I'm writing a windows application in C# using VS 2003. I got stuck where it has to write multiple output text files. Here's my piece of code: for loop { Random r = new Random();...
5
by: maral | last post by:
Hi every one, this is my first post here! I'm using GATE toolkit for information retrieval and text analysis, but i really need java for some parts. I have managed to find a specific word in...
1
by: Dave Mallett | last post by:
very new to Access. Trying to export query results via macro and transfertext, but keep getting error message stating "Microsoft Jet Engine cannot find the object 'HRQ-DM_Prd1_qtr.txt'. Make sure...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...

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.