473,320 Members | 2,145 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,320 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 6536
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...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.