OutPut the results of a select query to a *.TXT file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after the
archive it would be nice. skipping unecessary steps is a cool thing. also,
can i bypass the select query and just output the results of the delete query
before the info is gone? not asking much huh
thanks
 
Hi, Joe.
i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain three
columns of data, ID, Junk, and FromDate. The formatting of the data types
will be automatic, since Jet will automatically create a Schema.ini file in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.
 
thanks Gunny, i'll put it to work in the morning and let you know how it goes.

'69 Camaro said:
Hi, Joe.
i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain three
columns of data, ID, Junk, and FromDate. The formatting of the data types
will be automatic, since Jet will automatically create a Schema.ini file in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.


Joe Mills said:
i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after the
archive it would be nice. skipping unecessary steps is a cool thing. also,
can i bypass the select query and just output the results of the delete query
before the info is gone? not asking much huh
thanks
 
You're welcome, Joe. Good luck on it.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.


Joe Mills said:
thanks Gunny, i'll put it to work in the morning and let you know how it goes.

'69 Camaro said:
Hi, Joe.
i'm trying to create a *.TXT file as an archive from the results of a
select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain three
columns of data, ID, Junk, and FromDate. The formatting of the data types
will be automatic, since Jet will automatically create a Schema.ini file in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.


Joe Mills said:
i'm trying to create a *.TXT file as an archive from the results of a
select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after the
archive it would be nice. skipping unecessary steps is a cool thing. also,
can i bypass the select query and just output the results of the delete
query
before the info is gone? not asking much huh
thanks
 
Today I have learned something - thanks.

'69 Camaro said:
Hi, Joe.
i'm trying to create a *.TXT file as an archive from the results of a
select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain three
columns of data, ID, Junk, and FromDate. The formatting of the data types
will be automatic, since Jet will automatically create a Schema.ini file
in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


Joe Mills said:
i'm trying to create a *.TXT file as an archive from the results of a
select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after the
archive it would be nice. skipping unecessary steps is a cool thing.
also,
can i bypass the select query and just output the results of the delete
query
before the info is gone? not asking much huh
thanks
 
You're welcome, David. Glad I could be of some service. :-)

Happy New Year!
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.


David F Cox said:
Today I have learned something - thanks.

'69 Camaro said:
Hi, Joe.
i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain three
columns of data, ID, Junk, and FromDate. The formatting of the data types
will be automatic, since Jet will automatically create a Schema.ini file in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.


Joe Mills said:
i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after the
archive it would be nice. skipping unecessary steps is a cool thing. also,
can i bypass the select query and just output the results of the delete
query
before the info is gone? not asking much huh
thanks
 
Gunny,
i'm one of those guys that likes to know why things work, not just how. can
you make sure i'm getting this right please.
CodeLine1: "SELECT" (this tells it that the data comes from a query?), ",
ID" (field1?), ", Junk" (field2?). ", FromDate" (field3?), ....etc?
CodeLine2: "INTO" (what and where to put it?), "[Text (output type?);
HDR=YES (don't know this?), "DATABASE=C:\Work\]." (where to put it?),
"Stuff.txt" (what to call it?)
CodeLine3: "FROM tblStuff" (where did tblStuff come from?)
CodeLine4: "WHERE (ID<20);" (why a criteria clause? i want all of it to go.)

in CodeLine1 do i have to spell out every field with a comma in between?
that could take awhile since the query selects all the fields from six tables
most of which have more than 20 fields.
this way when i screw things up i'll have a better idea of where to fix it.

'69 Camaro said:
Hi, Joe.
i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain three
columns of data, ID, Junk, and FromDate. The formatting of the data types
will be automatic, since Jet will automatically create a Schema.ini file in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.


Joe Mills said:
i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after the
archive it would be nice. skipping unecessary steps is a cool thing. also,
can i bypass the select query and just output the results of the delete query
before the info is gone? not asking much huh
thanks
 
What Gunny gave you is the SQL of a query that will do what you want.

Don't think of it as four lines of code: it's a single SQL statement that
Gunny chose to display on four lines. No offense, but if you're going to
work with Access, you really should learn SQL.

To adapt it to your situation, create a query that returns all of the data
you want. Yes, you should specify specific fields, rather than use SELECT *,
in your query. Once the query is working how you want it to, go into the SQL
of the query (look under the View option on the menu when you've got the
query open) and add the text

INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt

before the FROM keyword of the query.

As you supposed, the INTO keyword tells Access to store a copy of the data
retrieved "somewhere". The "somewhere" is defined by the combination of
what's in square brackets and the .Stuff.txt afterwards. What Gunny's got
will create a file named C:\Work\Stuff.txt that contains the data.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
Gunny,
i'm one of those guys that likes to know why things work, not just how.
can
you make sure i'm getting this right please.
CodeLine1: "SELECT" (this tells it that the data comes from a query?), ",
ID" (field1?), ", Junk" (field2?). ", FromDate" (field3?), ....etc?
CodeLine2: "INTO" (what and where to put it?), "[Text (output type?);
HDR=YES (don't know this?), "DATABASE=C:\Work\]." (where to put it?),
"Stuff.txt" (what to call it?)
CodeLine3: "FROM tblStuff" (where did tblStuff come from?)
CodeLine4: "WHERE (ID<20);" (why a criteria clause? i want all of it to
go.)

in CodeLine1 do i have to spell out every field with a comma in between?
that could take awhile since the query selects all the fields from six
tables
most of which have more than 20 fields.
this way when i screw things up i'll have a better idea of where to fix
it.

'69 Camaro said:
Hi, Joe.
i'm trying to create a *.TXT file as an archive from the results of a
select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text
file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain three
columns of data, ID, Junk, and FromDate. The formatting of the data
types
will be automatic, since Jet will automatically create a Schema.ini file
in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


Joe Mills said:
i'm trying to create a *.TXT file as an archive from the results of a
select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after
the
archive it would be nice. skipping unecessary steps is a cool thing.
also,
can i bypass the select query and just output the results of the delete
query
before the info is gone? not asking much huh
thanks
 
believe me, NO offense taken! learning SQL is at the top of my ToDo list.
thank you for being specific about how and where to put the code. i did
create the query using SELECT* for each of the tables instead of naming each
field as there are a couple hundred fields. the query works great. is that
going to cause a problem after inserting the SQL statement? do you need (or
even want) more info as to what my application is for/doing to better
understand where i'm at?
i've read a lot of responses by you and Gunny and my opinion is, i couldn't
be in better hands. thank you very much


Douglas J. Steele said:
What Gunny gave you is the SQL of a query that will do what you want.

Don't think of it as four lines of code: it's a single SQL statement that
Gunny chose to display on four lines. No offense, but if you're going to
work with Access, you really should learn SQL.

To adapt it to your situation, create a query that returns all of the data
you want. Yes, you should specify specific fields, rather than use SELECT *,
in your query. Once the query is working how you want it to, go into the SQL
of the query (look under the View option on the menu when you've got the
query open) and add the text

INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt

before the FROM keyword of the query.

As you supposed, the INTO keyword tells Access to store a copy of the data
retrieved "somewhere". The "somewhere" is defined by the combination of
what's in square brackets and the .Stuff.txt afterwards. What Gunny's got
will create a file named C:\Work\Stuff.txt that contains the data.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
Gunny,
i'm one of those guys that likes to know why things work, not just how.
can
you make sure i'm getting this right please.
CodeLine1: "SELECT" (this tells it that the data comes from a query?), ",
ID" (field1?), ", Junk" (field2?). ", FromDate" (field3?), ....etc?
CodeLine2: "INTO" (what and where to put it?), "[Text (output type?);
HDR=YES (don't know this?), "DATABASE=C:\Work\]." (where to put it?),
"Stuff.txt" (what to call it?)
CodeLine3: "FROM tblStuff" (where did tblStuff come from?)
CodeLine4: "WHERE (ID<20);" (why a criteria clause? i want all of it to
go.)

in CodeLine1 do i have to spell out every field with a comma in between?
that could take awhile since the query selects all the fields from six
tables
most of which have more than 20 fields.
this way when i screw things up i'll have a better idea of where to fix
it.

'69 Camaro said:
Hi, Joe.

i'm trying to create a *.TXT file as an archive from the results of a
select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text
file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain three
columns of data, ID, Junk, and FromDate. The formatting of the data
types
will be automatic, since Jet will automatically create a Schema.ini file
in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


:

i'm trying to create a *.TXT file as an archive from the results of a
select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after
the
archive it would be nice. skipping unecessary steps is a cool thing.
also,
can i bypass the select query and just output the results of the delete
query
before the info is gone? not asking much huh
thanks
 
Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't work, and
we'll see what we can do.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
believe me, NO offense taken! learning SQL is at the top of my ToDo list.
thank you for being specific about how and where to put the code. i did
create the query using SELECT* for each of the tables instead of naming
each
field as there are a couple hundred fields. the query works great. is
that
going to cause a problem after inserting the SQL statement? do you need
(or
even want) more info as to what my application is for/doing to better
understand where i'm at?
i've read a lot of responses by you and Gunny and my opinion is, i
couldn't
be in better hands. thank you very much


Douglas J. Steele said:
What Gunny gave you is the SQL of a query that will do what you want.

Don't think of it as four lines of code: it's a single SQL statement that
Gunny chose to display on four lines. No offense, but if you're going to
work with Access, you really should learn SQL.

To adapt it to your situation, create a query that returns all of the
data
you want. Yes, you should specify specific fields, rather than use SELECT
*,
in your query. Once the query is working how you want it to, go into the
SQL
of the query (look under the View option on the menu when you've got the
query open) and add the text

INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt

before the FROM keyword of the query.

As you supposed, the INTO keyword tells Access to store a copy of the
data
retrieved "somewhere". The "somewhere" is defined by the combination of
what's in square brackets and the .Stuff.txt afterwards. What Gunny's got
will create a file named C:\Work\Stuff.txt that contains the data.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
Gunny,
i'm one of those guys that likes to know why things work, not just how.
can
you make sure i'm getting this right please.
CodeLine1: "SELECT" (this tells it that the data comes from a query?),
",
ID" (field1?), ", Junk" (field2?). ", FromDate" (field3?), ....etc?
CodeLine2: "INTO" (what and where to put it?), "[Text (output type?);
HDR=YES (don't know this?), "DATABASE=C:\Work\]." (where to put it?),
"Stuff.txt" (what to call it?)
CodeLine3: "FROM tblStuff" (where did tblStuff come from?)
CodeLine4: "WHERE (ID<20);" (why a criteria clause? i want all of it to
go.)

in CodeLine1 do i have to spell out every field with a comma in
between?
that could take awhile since the query selects all the fields from six
tables
most of which have more than 20 fields.
this way when i screw things up i'll have a better idea of where to fix
it.

:

Hi, Joe.

i'm trying to create a *.TXT file as an archive from the results of
a
select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text
file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain
three
columns of data, ID, Junk, and FromDate. The formatting of the data
types
will be automatic, since Jet will automatically create a Schema.ini
file
in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and
tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for
contact
info.


:

i'm trying to create a *.TXT file as an archive from the results of
a
select
query before a delete query wipes out the information. if i can
avoid
dumping it into a temporary table first then deleting the table
after
the
archive it would be nice. skipping unecessary steps is a cool thing.
also,
can i bypass the select query and just output the results of the
delete
query
before the info is gone? not asking much huh
thanks
 
i put in this code: INTO [Text; HDR=Yes; Database=C:\].Archive.txt
it's says it can't find "Archive.mdb"
i'm not trying to save it to another database, it's just supposed to be a
backup .TXT file of the data in the record they are deleting in case they
change their mind after the delete. am i trying to be too nice to the users?
the deleted data will probably never be needed again.

Douglas J. Steele said:
Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't work, and
we'll see what we can do.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
believe me, NO offense taken! learning SQL is at the top of my ToDo list.
thank you for being specific about how and where to put the code. i did
create the query using SELECT* for each of the tables instead of naming
each
field as there are a couple hundred fields. the query works great. is
that
going to cause a problem after inserting the SQL statement? do you need
(or
even want) more info as to what my application is for/doing to better
understand where i'm at?
i've read a lot of responses by you and Gunny and my opinion is, i
couldn't
be in better hands. thank you very much


Douglas J. Steele said:
What Gunny gave you is the SQL of a query that will do what you want.

Don't think of it as four lines of code: it's a single SQL statement that
Gunny chose to display on four lines. No offense, but if you're going to
work with Access, you really should learn SQL.

To adapt it to your situation, create a query that returns all of the
data
you want. Yes, you should specify specific fields, rather than use SELECT
*,
in your query. Once the query is working how you want it to, go into the
SQL
of the query (look under the View option on the menu when you've got the
query open) and add the text

INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt

before the FROM keyword of the query.

As you supposed, the INTO keyword tells Access to store a copy of the
data
retrieved "somewhere". The "somewhere" is defined by the combination of
what's in square brackets and the .Stuff.txt afterwards. What Gunny's got
will create a file named C:\Work\Stuff.txt that contains the data.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Gunny,
i'm one of those guys that likes to know why things work, not just how.
can
you make sure i'm getting this right please.
CodeLine1: "SELECT" (this tells it that the data comes from a query?),
",
ID" (field1?), ", Junk" (field2?). ", FromDate" (field3?), ....etc?
CodeLine2: "INTO" (what and where to put it?), "[Text (output type?);
HDR=YES (don't know this?), "DATABASE=C:\Work\]." (where to put it?),
"Stuff.txt" (what to call it?)
CodeLine3: "FROM tblStuff" (where did tblStuff come from?)
CodeLine4: "WHERE (ID<20);" (why a criteria clause? i want all of it to
go.)

in CodeLine1 do i have to spell out every field with a comma in
between?
that could take awhile since the query selects all the fields from six
tables
most of which have more than 20 fields.
this way when i screw things up i'll have a better idea of where to fix
it.

:

Hi, Joe.

i'm trying to create a *.TXT file as an archive from the results of
a
select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a text
file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain
three
columns of data, ID, Junk, and FromDate. The formatting of the data
types
will be automatic, since Jet will automatically create a Schema.ini
file
in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and
tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for
contact
info.


:

i'm trying to create a *.TXT file as an archive from the results of
a
select
query before a delete query wipes out the information. if i can
avoid
dumping it into a temporary table first then deleting the table
after
the
archive it would be nice. skipping unecessary steps is a cool thing.
also,
can i bypass the select query and just output the results of the
delete
query
before the info is gone? not asking much huh
thanks
 
i'm trying to create a *.TXT file as an archive from the results of a select
query before a delete query wipes out the information. if i can avoid
dumping it into a temporary table first then deleting the table after the
archive it would be nice. skipping unecessary steps is a cool thing. also,
can i bypass the select query and just output the results of the delete query
before the info is gone? not asking much huh
thanks

I think Gunny's INTO option can be made to work - but if you have
trouble with it, take a look into using VBA code with the TransferText
method to export the data to a text file. Open the VBA editor and look
for help on TransferText.

John W. Vinson[MVP]
 
Try INTO [Text; HDR=Yes; Database=C:\.Archive.txt]


Joe Mills said:
i put in this code: INTO [Text; HDR=Yes; Database=C:\].Archive.txt
it's says it can't find "Archive.mdb"
i'm not trying to save it to another database, it's just supposed to be a
backup .TXT file of the data in the record they are deleting in case they
change their mind after the delete. am i trying to be too nice to the
users?
the deleted data will probably never be needed again.

Douglas J. Steele said:
Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't work,
and
we'll see what we can do.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
believe me, NO offense taken! learning SQL is at the top of my ToDo
list.
thank you for being specific about how and where to put the code. i
did
create the query using SELECT* for each of the tables instead of naming
each
field as there are a couple hundred fields. the query works great. is
that
going to cause a problem after inserting the SQL statement? do you
need
(or
even want) more info as to what my application is for/doing to better
understand where i'm at?
i've read a lot of responses by you and Gunny and my opinion is, i
couldn't
be in better hands. thank you very much


:

What Gunny gave you is the SQL of a query that will do what you want.

Don't think of it as four lines of code: it's a single SQL statement
that
Gunny chose to display on four lines. No offense, but if you're going
to
work with Access, you really should learn SQL.

To adapt it to your situation, create a query that returns all of the
data
you want. Yes, you should specify specific fields, rather than use
SELECT
*,
in your query. Once the query is working how you want it to, go into
the
SQL
of the query (look under the View option on the menu when you've got
the
query open) and add the text

INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt

before the FROM keyword of the query.

As you supposed, the INTO keyword tells Access to store a copy of the
data
retrieved "somewhere". The "somewhere" is defined by the combination
of
what's in square brackets and the .Stuff.txt afterwards. What Gunny's
got
will create a file named C:\Work\Stuff.txt that contains the data.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Gunny,
i'm one of those guys that likes to know why things work, not just
how.
can
you make sure i'm getting this right please.
CodeLine1: "SELECT" (this tells it that the data comes from a
query?),
",
ID" (field1?), ", Junk" (field2?). ", FromDate" (field3?), ....etc?
CodeLine2: "INTO" (what and where to put it?), "[Text (output
type?);
HDR=YES (don't know this?), "DATABASE=C:\Work\]." (where to put
it?),
"Stuff.txt" (what to call it?)
CodeLine3: "FROM tblStuff" (where did tblStuff come from?)
CodeLine4: "WHERE (ID<20);" (why a criteria clause? i want all of it
to
go.)

in CodeLine1 do i have to spell out every field with a comma in
between?
that could take awhile since the query selects all the fields from
six
tables
most of which have more than 20 fields.
this way when i screw things up i'll have a better idea of where to
fix
it.

:

Hi, Joe.

i'm trying to create a *.TXT file as an archive from the results
of
a
select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a
text
file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain
three
columns of data, ID, Junk, and FromDate. The formatting of the
data
types
will be automatic, since Jet will automatically create a Schema.ini
file
in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and
tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for
contact
info.


:

i'm trying to create a *.TXT file as an archive from the results
of
a
select
query before a delete query wipes out the information. if i can
avoid
dumping it into a temporary table first then deleting the table
after
the
archive it would be nice. skipping unecessary steps is a cool
thing.
also,
can i bypass the select query and just output the results of the
delete
query
before the info is gone? not asking much huh
thanks
 
Works fine for me.

What's the exact SQL you're trying to run now?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
i put in this code: INTO [Text; HDR=Yes; Database=C:\].Archive.txt
it's says it can't find "Archive.mdb"
i'm not trying to save it to another database, it's just supposed to be a
backup .TXT file of the data in the record they are deleting in case they
change their mind after the delete. am i trying to be too nice to the
users?
the deleted data will probably never be needed again.

Douglas J. Steele said:
Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't work,
and
we'll see what we can do.
 
i'm wondering if i'm just wasting all your valuable time (the need for a
backup). the user has to confirm the delete anyway so if it's gone, tough
crap it's their problem?
off-the-subject question: how do the pros like yourself protect your
applications from unauthorized duplication? are there copywrite issues i
need to be aware of? i'm obviously a new developer and want to cover my
financial butt. the application i'm writing has the potential to be sold to
literally thousands of institutions (happened to stumble on a nationwide
problem that this will solve) and i, naturally, want the credit. would i
sell it as a license agreement? if so, your thoughts on fees?
thank you for your interest
 
it gives me an error saying...'Text; HDR=Yes; Database=C:\Archive.txt' is not
a valid name. i noticed that you have a period (.) before and after Archive,
is that the problem?

David F Cox said:
Try INTO [Text; HDR=Yes; Database=C:\.Archive.txt]


Joe Mills said:
i put in this code: INTO [Text; HDR=Yes; Database=C:\].Archive.txt
it's says it can't find "Archive.mdb"
i'm not trying to save it to another database, it's just supposed to be a
backup .TXT file of the data in the record they are deleting in case they
change their mind after the delete. am i trying to be too nice to the
users?
the deleted data will probably never be needed again.

Douglas J. Steele said:
Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't work,
and
we'll see what we can do.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


believe me, NO offense taken! learning SQL is at the top of my ToDo
list.
thank you for being specific about how and where to put the code. i
did
create the query using SELECT* for each of the tables instead of naming
each
field as there are a couple hundred fields. the query works great. is
that
going to cause a problem after inserting the SQL statement? do you
need
(or
even want) more info as to what my application is for/doing to better
understand where i'm at?
i've read a lot of responses by you and Gunny and my opinion is, i
couldn't
be in better hands. thank you very much


:

What Gunny gave you is the SQL of a query that will do what you want.

Don't think of it as four lines of code: it's a single SQL statement
that
Gunny chose to display on four lines. No offense, but if you're going
to
work with Access, you really should learn SQL.

To adapt it to your situation, create a query that returns all of the
data
you want. Yes, you should specify specific fields, rather than use
SELECT
*,
in your query. Once the query is working how you want it to, go into
the
SQL
of the query (look under the View option on the menu when you've got
the
query open) and add the text

INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt

before the FROM keyword of the query.

As you supposed, the INTO keyword tells Access to store a copy of the
data
retrieved "somewhere". The "somewhere" is defined by the combination
of
what's in square brackets and the .Stuff.txt afterwards. What Gunny's
got
will create a file named C:\Work\Stuff.txt that contains the data.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Gunny,
i'm one of those guys that likes to know why things work, not just
how.
can
you make sure i'm getting this right please.
CodeLine1: "SELECT" (this tells it that the data comes from a
query?),
",
ID" (field1?), ", Junk" (field2?). ", FromDate" (field3?), ....etc?
CodeLine2: "INTO" (what and where to put it?), "[Text (output
type?);
HDR=YES (don't know this?), "DATABASE=C:\Work\]." (where to put
it?),
"Stuff.txt" (what to call it?)
CodeLine3: "FROM tblStuff" (where did tblStuff come from?)
CodeLine4: "WHERE (ID<20);" (why a criteria clause? i want all of it
to
go.)

in CodeLine1 do i have to spell out every field with a comma in
between?
that could take awhile since the query selects all the fields from
six
tables
most of which have more than 20 fields.
this way when i screw things up i'll have a better idea of where to
fix
it.

:

Hi, Joe.

i'm trying to create a *.TXT file as an archive from the results
of
a
select
query before a delete query wipes out the information.

This is the syntax of the SQL query to save a SELECT query as a
text
file:

SELECT ID, Junk, FromDate
INTO [Text;HDR=YES;DATABASE=C:\Work\].Stuff.txt
FROM tblStuff
WHERE (ID<20);

The resulting text file will be C:\Work\Stuff.txt and will contain
three
columns of data, ID, Junk, and FromDate. The formatting of the
data
types
will be automatic, since Jet will automatically create a Schema.ini
file
in
the destination directory.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and
tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for
contact
info.


:

i'm trying to create a *.TXT file as an archive from the results
of
a
select
query before a delete query wipes out the information. if i can
avoid
dumping it into a temporary table first then deleting the table
after
the
archive it would be nice. skipping unecessary steps is a cool
thing.
also,
can i bypass the select query and just output the results of the
delete
query
before the info is gone? not asking much huh
thanks
 
didn't work for me (see my reply to Mr. Cox)
here's the SQL i'm using:
SELECT Residents.ID, Residents.*, Admission.*, Devices.*, Skin.*,
Property.*, [Physical and Structural].*, Vitals.*
INTO [Text; HDR=Yes; Database=C:\Archive.txt]
FROM (((((Residents INNER JOIN Admission ON Residents.ID=Admission.ID) INNER
JOIN Devices ON Admission.Key=Devices.Key) INNER JOIN Skin ON
(Devices.Key=Skin.Key) AND (Admission.Key=Skin.Key)) INNER JOIN Property ON
(Devices.Key=Property.Key) AND (Admission.Key=Property.Key)) INNER JOIN
[Physical and Structural] ON (Devices.Key=[Physical and Structural].Key) AND
(Admission.Key=[Physical and Structural].Key)) INNER JOIN Vitals ON
(Devices.Key=Vitals.Key) AND (Admission.Key=Vitals.Key)
WHERE (((Residents.ID)=Forms!DeleteResident.ID));


Douglas J. Steele said:
Works fine for me.

What's the exact SQL you're trying to run now?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
i put in this code: INTO [Text; HDR=Yes; Database=C:\].Archive.txt
it's says it can't find "Archive.mdb"
i'm not trying to save it to another database, it's just supposed to be a
backup .TXT file of the data in the record they are deleting in case they
change their mind after the delete. am i trying to be too nice to the
users?
the deleted data will probably never be needed again.

Douglas J. Steele said:
Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't work,
and
we'll see what we can do.
 
Your original post said you were using INTO [Text; HDR=Yes;
Database=C:\].Archive.txt, but the SQL below has INTO [Text; HDR=Yes;
Database=C:\Archive.txt]

The location of the closing square bracket is important: the folder name
goes inside the square brackets, but the file name is outside (with a period
in front of it)

You may have to put the actual field names in, though. Access will be
creating a file named schema.ini in the same folder as the text file, and
I'm not sure whether it will accept the * instead (sorry, too lazy to test)

And sorry I can't help you with your question about unauthorized
duplication. What databases I design at work are the property of the
company, not me, and what code I post on the internet, on my website and in
the articles I write, I don't care if others use it.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
didn't work for me (see my reply to Mr. Cox)
here's the SQL i'm using:
SELECT Residents.ID, Residents.*, Admission.*, Devices.*, Skin.*,
Property.*, [Physical and Structural].*, Vitals.*
INTO [Text; HDR=Yes; Database=C:\Archive.txt]
FROM (((((Residents INNER JOIN Admission ON Residents.ID=Admission.ID)
INNER
JOIN Devices ON Admission.Key=Devices.Key) INNER JOIN Skin ON
(Devices.Key=Skin.Key) AND (Admission.Key=Skin.Key)) INNER JOIN Property
ON
(Devices.Key=Property.Key) AND (Admission.Key=Property.Key)) INNER JOIN
[Physical and Structural] ON (Devices.Key=[Physical and Structural].Key)
AND
(Admission.Key=[Physical and Structural].Key)) INNER JOIN Vitals ON
(Devices.Key=Vitals.Key) AND (Admission.Key=Vitals.Key)
WHERE (((Residents.ID)=Forms!DeleteResident.ID));


Douglas J. Steele said:
Works fine for me.

What's the exact SQL you're trying to run now?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
i put in this code: INTO [Text; HDR=Yes; Database=C:\].Archive.txt
it's says it can't find "Archive.mdb"
i'm not trying to save it to another database, it's just supposed to be
a
backup .TXT file of the data in the record they are deleting in case
they
change their mind after the delete. am i trying to be too nice to the
users?
the deleted data will probably never be needed again.

:

Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't
work,
and
we'll see what we can do.
 
will give it a shot, thank you.

Douglas J. Steele said:
Your original post said you were using INTO [Text; HDR=Yes;
Database=C:\].Archive.txt, but the SQL below has INTO [Text; HDR=Yes;
Database=C:\Archive.txt]

The location of the closing square bracket is important: the folder name
goes inside the square brackets, but the file name is outside (with a period
in front of it)

You may have to put the actual field names in, though. Access will be
creating a file named schema.ini in the same folder as the text file, and
I'm not sure whether it will accept the * instead (sorry, too lazy to test)

And sorry I can't help you with your question about unauthorized
duplication. What databases I design at work are the property of the
company, not me, and what code I post on the internet, on my website and in
the articles I write, I don't care if others use it.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
didn't work for me (see my reply to Mr. Cox)
here's the SQL i'm using:
SELECT Residents.ID, Residents.*, Admission.*, Devices.*, Skin.*,
Property.*, [Physical and Structural].*, Vitals.*
INTO [Text; HDR=Yes; Database=C:\Archive.txt]
FROM (((((Residents INNER JOIN Admission ON Residents.ID=Admission.ID)
INNER
JOIN Devices ON Admission.Key=Devices.Key) INNER JOIN Skin ON
(Devices.Key=Skin.Key) AND (Admission.Key=Skin.Key)) INNER JOIN Property
ON
(Devices.Key=Property.Key) AND (Admission.Key=Property.Key)) INNER JOIN
[Physical and Structural] ON (Devices.Key=[Physical and Structural].Key)
AND
(Admission.Key=[Physical and Structural].Key)) INNER JOIN Vitals ON
(Devices.Key=Vitals.Key) AND (Admission.Key=Vitals.Key)
WHERE (((Residents.ID)=Forms!DeleteResident.ID));


Douglas J. Steele said:
Works fine for me.

What's the exact SQL you're trying to run now?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


i put in this code: INTO [Text; HDR=Yes; Database=C:\].Archive.txt
it's says it can't find "Archive.mdb"
i'm not trying to save it to another database, it's just supposed to be
a
backup .TXT file of the data in the record they are deleting in case
they
change their mind after the delete. am i trying to be too nice to the
users?
the deleted data will probably never be needed again.

:

Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't
work,
and
we'll see what we can do.
 
I am using 2007 Beta, and have tried it. The original syntax given (despite
looking odd to me) is the only one that works a bit, and only sometimes, for
me. When I say works a bit it will only work for my ID PK field, and ignores
other fields.



Douglas J. Steele said:
Works fine for me.

What's the exact SQL you're trying to run now?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe Mills said:
i put in this code: INTO [Text; HDR=Yes; Database=C:\].Archive.txt
it's says it can't find "Archive.mdb"
i'm not trying to save it to another database, it's just supposed to be a
backup .TXT file of the data in the record they are deleting in case they
change their mind after the delete. am i trying to be too nice to the
users?
the deleted data will probably never be needed again.

Douglas J. Steele said:
Just try making the suggested change and seeing whether it works.

If it does, you're fine. If it doesn't, post back with what didn't work,
and
we'll see what we can do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top