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

Export records to text file?

Hi,

I'm trying to come up with a way of generating 'warning' e-mails based on
specific criteria within an Access (2003) database. I've decided to do this
by exporting specific information to a text file which then gets parsed by a
simple shell program and processed by a 3rd party SMTP engine (Blat).

With my VERY limited knowledge of VB and Access coding, this is what I've
come up with so far:-
Private Sub Command0_Click()

Dim aSQL, bSQL, drop As String
Dim rs As Recordset
Dim db As Database

Set db = CurrentDb

drop = "DROP TABLE temp"
aSQL = "SELECT mytable.stuff INTO temp FROM mytable WHERE mytable.flag=0"
bSQL = "UPDATE mytable SET mytable.flag = 1 WHERE mytable.flag=0"

' Copy flagged records into temporary table
db.Execute aSQL

' Reset flag
db.Execute bSQL

' Export contents of temporary table to text file
Set rs = db.OpenRecordset("SELECT * FROM temp")
Open "c:\myfile.txt" For Append As #1
Write #1, Somehow put some records here!!!
Close #1

' Get rid of temporary table
db.Execute drop

End Sub
Can anyone tell me if I'm vaguely heading in the right direction and also
offer some advice in terms of actually writing the recordset into the text
file?

Many thanks in advance!

Andy

P.S. If this isn't the best NG for this please can someone point me in the
right direction - I've also posted to microsoft.public.access.
Nov 13 '05 #1
2 7208
Using the TransferText method would be simpler than using VBA file output
commands.

I'm not really sure why you're using a temporary table, though. Couldn't you
simply create a query

SELECT mytable.stuff FROM mytable WHERE mytable.flag=0

and export that query?

If you decide to use the VBA file output (and there's really nothing wrong
with it), I would strongly suggest not simply using #1 as the file tag,
especially if other applications are going to be running at the same time.
Look up the FreeFile function in the Help file.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Pecanfan" <pe******@no.spam> wrote in message
news:11***************@smtp-1.griffin.com...
Hi,

I'm trying to come up with a way of generating 'warning' e-mails based on
specific criteria within an Access (2003) database. I've decided to do this by exporting specific information to a text file which then gets parsed by a simple shell program and processed by a 3rd party SMTP engine (Blat).

With my VERY limited knowledge of VB and Access coding, this is what I've
come up with so far:-
Private Sub Command0_Click()

Dim aSQL, bSQL, drop As String
Dim rs As Recordset
Dim db As Database

Set db = CurrentDb

drop = "DROP TABLE temp"
aSQL = "SELECT mytable.stuff INTO temp FROM mytable WHERE mytable.flag=0"
bSQL = "UPDATE mytable SET mytable.flag = 1 WHERE mytable.flag=0"

' Copy flagged records into temporary table
db.Execute aSQL

' Reset flag
db.Execute bSQL

' Export contents of temporary table to text file
Set rs = db.OpenRecordset("SELECT * FROM temp")
Open "c:\myfile.txt" For Append As #1
Write #1, Somehow put some records here!!!
Close #1

' Get rid of temporary table
db.Execute drop

End Sub
Can anyone tell me if I'm vaguely heading in the right direction and also
offer some advice in terms of actually writing the recordset into the text
file?

Many thanks in advance!

Andy

P.S. If this isn't the best NG for this please can someone point me in the
right direction - I've also posted to microsoft.public.access.

Nov 13 '05 #2
> Using the TransferText method would be simpler than using VBA file output
commands.
I did consider this but I couldn't find a way of appending to the text file
using this method. Am I missing something here?
I'm not really sure why you're using a temporary table, though. Couldn't you simply create a query


I did have a good reason for this, but can't remember for the life of me
what it was. :-)

Cheers for the info!

Andy
Nov 13 '05 #3

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

Similar topics

1
by: Charlie | last post by:
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...
1
by: Bridget Willey | last post by:
I am using ACT 6 and am trying to "split" the database between records for customers and junk records. The accounts designated as "customers" have that word in the ID field, and I am using that...
6
by: Robin Cushman | last post by:
Hi all, I need some help -- I'm working with an A2K database, using DAO, and am trying to read records into a Crystal Report and then export it to a folder on our network as an Excel...
4
by: Jay | last post by:
This is a strange one that I can't seem to find a fix for. We have a Billing DB application (Access 2000 format) where we upload billing info in a comma delimited text file to our printer who...
10
by: Neil | last post by:
Hi guyz, just trying out this google feature so if i post if in the wrong area i appologize. now to my question. BTW i'm new to access programming, i've done a little vb6.0 and vb.net but access...
14
by: bonehead | last post by:
Greetings, I'm using the DoCmd.TransferText method to export the results of a MS Access query to a csv file. The csv will then be used to load an Oracle table. In other systems such as TOAD...
9
by: NEWSGROUPS | last post by:
I have data in a table in an Access 2000 database that needs to be exported to a formatted text file. For instance, the first field is an account number that is formatted in the table as text and...
2
by: Sashi | last post by:
Hi All, I have a table from which I want to export the data as a plain text file. I exported the data using the "Export" option and selected the comma as a separator and the " as the Text...
4
by: grumpydadtl | last post by:
I am exporting a text file from Access that will be fed into a mainframe application (third party - not something I manage). The file contains a header record, body - which is the variable number of...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...

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.