473,574 Members | 3,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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).sht ml
// (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 6572
In article <95************ *************@p osting.google.c om>,
ad***@mentorele ctronics.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).sht ml
// (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 sCreateStaticHT MLFiles()
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.OpenRecordse t(strSQL)
If Not (rs.BOF And rs.EOF) Then
strHTMLFile = "D:\Test0.h tm"
intHTMLFile = FreeFile
Open strHTMLFile For Output As intHTMLFile
Print #intHTMLFile, "<html><body><t able>"
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.OpenRecordse t(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><t able>"
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
1897
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 solution, I would be interested. Thank you. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load...
2
1730
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.) in one master document. I'm not exactly sure which is the most efficient method of going about this. Should I: a. Use a container file like a CAB...
5
3423
by: Buddhist[CHinA] | last post by:
The text files are not only the .txt files, but also all ascii files. Thx.
2
2706
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 the simplest way to state it. Is there a way to write to text files and save them as different names (presumably one of the variables dot "TXT")...
3
5679
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 //Propagation constants are elements of the vector beta for(int j=0;j<(int)(number_of_nodes);j++){ if(*(beta+j)>substrate*k && *(beta+i)<core*k){...
6
30664
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 know I need to use os.path.walk() to walk through all the files, and if not os.path.isdir(filename) with open(filename,'r').read() to read all the files...
3
3136
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
4182
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(); //use millisecond and random to avoid similar filename
5
14633
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 one text file, but i need to look for a specific word, in multiple text files. all of the files are ".txt" and they are in the same folder but each of...
1
1957
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 the object exists and that you spell its name and path correctly". I don't understand why it's saying that it can't find the 'object'...I'm...
0
7764
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8111
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7863
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8140
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5336
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1375
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1102
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.