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

exporting query to text file [help!]

hi,
I have a query that visualizes me, according to some criterions from
me inserted, name , Surname , Address , phone
ok..

Now, through a button, positioned in a Form,
I have to only export from this query the field telephone in a text
file
the name of the text file I would like to choose me...

the text file example:

345368998756
345894614542
168416616464
165445648250

they will have to appear a telephone number on every line without any
; or "
as in the example that I have done here above..
can someone help me? some example of code?
thanks
alexia
i'm access newbie.....
[I am desperate]

Nov 12 '05 #1
12 7475
"alessia" <al*************@yahoo.it> wrote in message
news:gv********************************@4ax.com...
hi,
I have a query that visualizes me, according to some criterions from
me inserted, name , Surname , Address , phone
ok..

Now, through a button, positioned in a Form,
I have to only export from this query the field telephone in a text
file
the name of the text file I would like to choose me...

the text file example:

345368998756
345894614542
168416616464
165445648250

they will have to appear a telephone number on every line without any
; or "
as in the example that I have done here above..
can someone help me? some example of code?
thanks
alexia
i'm access newbie.....
[I am desperate]


Create a new query "qryExport" which is based on your first query but
selects only the phone number. Then, if the button on your form is named
'cmdExport' the code might be as shown below. Note that if you need a
better way to select the export file path, then there is code for this too.

Private Sub cmdExport_Click()

On Error GoTo Err_Handler

Dim strPath As String

strPath = InputBox("Enter file path", , "C:\Shared\Test.txt")

If Len(strPath) = 0 Then Exit Sub

DoCmd.TransferText acExportDelim, , "qryExport", strPath

MsgBox "Done", vbInformation

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Nov 12 '05 #2
Il Fri, 10 Oct 2003 08:06:24 +0000 (UTC), "Fletcher Arnold"
<fl****@home.com> ha scritto:
"alessia" <al*************@yahoo.it> wrote in message
news:gv********************************@4ax.com.. .
hi,
I have a query that visualizes me, according to some criterions from
me inserted, name , Surname , Address , phone
ok..

Now, through a button, positioned in a Form,
I have to only export from this query the field telephone in a text
file
the name of the text file I would like to choose me...

the text file example:

345368998756
345894614542
168416616464
165445648250

they will have to appear a telephone number on every line without any
; or "
as in the example that I have done here above..
can someone help me? some example of code?
thanks
alexia
i'm access newbie.....
[I am desperate]


Create a new query "qryExport" which is based on your first query but
selects only the phone number. Then, if the button on your form is named
'cmdExport' the code might be as shown below. Note that if you need a
better way to select the export file path, then there is code for this too.

Private Sub cmdExport_Click()

On Error GoTo Err_Handler

Dim strPath As String

strPath = InputBox("Enter file path", , "C:\Shared\Test.txt")

If Len(strPath) = 0 Then Exit Sub

DoCmd.TransferText acExportDelim, , "qryExport", strPath

MsgBox "Done", vbInformation

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub


thanks! you are kind.. I immediately try the code that you have given
me...
it excuses my bad English... I am Italian
good day

Nov 12 '05 #3
Il Sat, 11 Oct 2003 08:48:59 GMT, alessia <al*************@yahoo.it>
ha scritto:

Create a new query "qryExport" which is based on your first query but
selects only the phone number. Then, if the button on your form is named
'cmdExport' the code might be as shown below. Note that if you need a
better way to select the export file path, then there is code for this too.

Private Sub cmdExport_Click()

On Error GoTo Err_Handler

Dim strPath As String

strPath = InputBox("Enter file path", , "C:\Shared\Test.txt")

If Len(strPath) = 0 Then Exit Sub

DoCmd.TransferText acExportDelim, , "qryExport", strPath

MsgBox "Done", vbInformation

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub


OK, work! great! thanks Fletcher!

however when I open the created text file
the telephone numbers come me this way

"3332321415416385"
"5156468481565484"

how do I do for eliminating the " "??

I would like only the telephone number in this way

1515645166544
1454468468154

have a good day!
Nov 12 '05 #4
"alessia" <al*************@yahoo.it> wrote in message
news:k2********************************@4ax.com...
Il Sat, 11 Oct 2003 08:48:59 GMT, alessia <al*************@yahoo.it>
ha scritto:

Create a new query "qryExport" which is based on your first query but
selects only the phone number. Then, if the button on your form is named'cmdExport' the code might be as shown below. Note that if you need a
better way to select the export file path, then there is code for this too.
Private Sub cmdExport_Click()

On Error GoTo Err_Handler

Dim strPath As String

strPath = InputBox("Enter file path", , "C:\Shared\Test.txt")

If Len(strPath) = 0 Then Exit Sub

DoCmd.TransferText acExportDelim, , "qryExport", strPath

MsgBox "Done", vbInformation

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub


OK, work! great! thanks Fletcher!

however when I open the created text file
the telephone numbers come me this way

"3332321415416385"
"5156468481565484"

how do I do for eliminating the " "??

I would like only the telephone number in this way

1515645166544
1454468468154

have a good day!


There are a number of ways to do this. Perhaps the easiest is:

1. Select qryExport in the database window.
2. From the menu at the top choose File>Export
3. Select filename and type = text then press Export
4. On this screen you can press "Advanced"
5. Set up your options here - especially change text qualifier from " to
none
6. Choose Save as ..."QryExport Export Specification"
7. Finish export

You can now change the code from:
DoCmd.TransferText acExportDelim, , "qryExport", strPath
to:
DoCmd.TransferText acExportDelim, "QryExport Export Specification",
"qryExport", strPath
If this is too difficult I could write some code to do this for you.
Fletcher
Nov 12 '05 #5
Il Sat, 11 Oct 2003 12:19:58 +0000 (UTC), "Fletcher Arnold"
<fl****@home.com> ha scritto:
"alessia" <al*************@yahoo.it> wrote in message
news:k2********************************@4ax.com.. .
Il Sat, 11 Oct 2003 08:48:59 GMT, alessia <al*************@yahoo.it>
ha scritto:

>>Create a new query "qryExport" which is based on your first query but
>>selects only the phone number. Then, if the button on your form isnamed >>'cmdExport' the code might be as shown below. Note that if you need a
>>better way to select the export file path, then there is code for thistoo. >>
>>Private Sub cmdExport_Click()
>>
>> On Error GoTo Err_Handler
>>
>> Dim strPath As String
>>
>> strPath = InputBox("Enter file path", , "C:\Shared\Test.txt")
>>
>> If Len(strPath) = 0 Then Exit Sub
>>
>> DoCmd.TransferText acExportDelim, , "qryExport", strPath
>>
>> MsgBox "Done", vbInformation
>>
>>Exit_Handler:
>> Exit Sub
>>
>>Err_Handler:
>> MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
>> Resume Exit_Handler
>>
>>End Sub
>>


OK, work! great! thanks Fletcher!

however when I open the created text file
the telephone numbers come me this way

"3332321415416385"
"5156468481565484"

how do I do for eliminating the " "??

I would like only the telephone number in this way

1515645166544
1454468468154

have a good day!


There are a number of ways to do this. Perhaps the easiest is:

1. Select qryExport in the database window.
2. From the menu at the top choose File>Export
3. Select filename and type = text then press Export
4. On this screen you can press "Advanced"
5. Set up your options here - especially change text qualifier from " to
none
6. Choose Save as ..."QryExport Export Specification"
7. Finish export

You can now change the code from:
DoCmd.TransferText acExportDelim, , "qryExport", strPath
to:
DoCmd.TransferText acExportDelim, "QryExport Export Specification",
"qryExport", strPath
If this is too difficult I could write some code to do this for you.
Fletcher


thanks Fletcher! very much!

have a nice day!

Alessia.

Nov 12 '05 #6
Il Sat, 11 Oct 2003 22:50:16 GMT, alessia <al*************@yahoo.it>
ha scritto:
If this is too difficult I could write some code to do this for you.


I have tried what you have suggested me you, Fletcher, but I would
prefer to serve everything as code... I would not like to disturb too
much, and if you have of the of leisure time to write the code, I
would be thankful of it... if it doesn't find you possible...don't
worry you...I thank you... you have been kind indeed.
[i'm sorry my bad english...I hope is understood ]

alessia
Nov 12 '05 #7

"alessia" <al*************@yahoo.it> wrote in message
news:ti********************************@4ax.com...
Il Sat, 11 Oct 2003 22:50:16 GMT, alessia <al*************@yahoo.it>
ha scritto:
If this is too difficult I could write some code to do this for you.


I have tried what you have suggested me you, Fletcher, but I would
prefer to serve everything as code... I would not like to disturb too
much, and if you have of the of leisure time to write the code, I
would be thankful of it... if it doesn't find you possible...don't
worry you...I thank you... you have been kind indeed.
[i'm sorry my bad english...I hope is understood ]

alessia


Hi Alessia
I am glad that you got the code to work. Don't worry about your English -
its fine, and very polite!
The following code is one possible version. It assumes your query is
"qryExport" which contains the field "Tel" - if not change the lines:
Set rst = dbs.OpenRecordset("qryExport" ...
and
Print #intFile, Nz(rst!Tel, "")

When you paste the new code in, make sure you compile the code -
Debug>Compile. If it does not compile, check Tools>References and make sure
the box Microsoft DAO 3.6 Object Library is checked.

Good Luck

Fletcher
Private Sub cmdExport_Click()

On Error GoTo Err_Handler

Dim strPath As String
Dim intFile As Integer
Dim strLine As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

strPath = InputBox("Enter file path", _
"Export", _
"C:\Shared\Test.txt")

If Len(strPath) = 0 Then Exit Sub

If Len(Dir(strPath)) > 0 Then
If MsgBox("This file already exists" & vbCrLf & _
"Would you like to overwrite it?", _
vbExclamation Or vbYesNoCancel, _
"Export") <> vbYes Then Exit Sub
End If

intFile = FreeFile

Open strPath For Output As #intFile

Set dbs = CurrentDb

Set rst = dbs.OpenRecordset("qryExport", dbOpenForwardOnly)

While Not rst.EOF
Print #intFile, Nz(rst!Tel, "")
rst.MoveNext
Wend

MsgBox "Export routine complete", _
vbInformation, "Export"

Exit_Handler:

On Error Resume Next

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Close #intFile

Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub


Nov 12 '05 #8
Il Sun, 12 Oct 2003 20:15:58 +0000 (UTC), "Fletcher Arnold"
<fl****@home.com> ha scritto:

Hi Alessia
I am glad that you got the code to work. Don't worry about your English -
its fine, and very polite!
The following code is one possible version. It assumes your query is
"qryExport" which contains the field "Tel" - if not change the lines:
Set rst = dbs.OpenRecordset("qryExport" ...
and
Print #intFile, Nz(rst!Tel, "")

When you paste the new code in, make sure you compile the code -
Debug>Compile. If it does not compile, check Tools>References and make sure
the box Microsoft DAO 3.6 Object Library is checked.

Good Luck

Fletcher
Private Sub cmdExport_Click()

On Error GoTo Err_Handler

Dim strPath As String
Dim intFile As Integer
Dim strLine As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

strPath = InputBox("Enter file path", _
"Export", _
"C:\Shared\Test.txt")

If Len(strPath) = 0 Then Exit Sub

If Len(Dir(strPath)) > 0 Then
If MsgBox("This file already exists" & vbCrLf & _
"Would you like to overwrite it?", _
vbExclamation Or vbYesNoCancel, _
"Export") <> vbYes Then Exit Sub
End If

intFile = FreeFile

Open strPath For Output As #intFile

Set dbs = CurrentDb

Set rst = dbs.OpenRecordset("qryExport", dbOpenForwardOnly)

While Not rst.EOF
Print #intFile, Nz(rst!Tel, "")
rst.MoveNext
Wend

MsgBox "Export routine complete", _
vbInformation, "Export"

Exit_Handler:

On Error Resume Next

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Close #intFile

Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub


Ciao Super - Fletcher
I mind giving you so much trouble, I have copied the code that you
have given me, I have modified the interested lines, I have compiled
the program...I press the button, I insert the path and the name of
the file, and this error signals me...

Error No: 3061
non enough parameters. 3
[I hope both corrected the translation]

the file test.txt has been created... but it is empty..

I have modified only these lines

Set rst = dbs.OpenRecordset("query_fuoriorario_cell",
dbOpenForwardOnly)
and
Print #intFile, Nz(rst!cell, "")
query_fuori_orario : it's my export query
cell : it's a field of query_fuori_orario
according to you, as can I resolve this error??

I don't so finally disturb still you...

thx, Fletcher....

where r u from Fletcher?

i live in venice...

have a nice day!

Nov 12 '05 #9
"alessia" <al*************@yahoo.it> wrote in message
news:0i********************************@4ax.com...
Il Sun, 12 Oct 2003 20:15:58 +0000 (UTC), "Fletcher Arnold"
<fl****@home.com> ha scritto:

Hi Alessia
I am glad that you got the code to work. Don't worry about your English -its fine, and very polite!
The following code is one possible version. It assumes your query is
"qryExport" which contains the field "Tel" - if not change the lines:
Set rst = dbs.OpenRecordset("qryExport" ...
and
Print #intFile, Nz(rst!Tel, "")

When you paste the new code in, make sure you compile the code -
Debug>Compile. If it does not compile, check Tools>References and make surethe box Microsoft DAO 3.6 Object Library is checked.

Good Luck

Fletcher
Private Sub cmdExport_Click()

On Error GoTo Err_Handler

Dim strPath As String
Dim intFile As Integer
Dim strLine As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

strPath = InputBox("Enter file path", _
"Export", _
"C:\Shared\Test.txt")

If Len(strPath) = 0 Then Exit Sub

If Len(Dir(strPath)) > 0 Then
If MsgBox("This file already exists" & vbCrLf & _
"Would you like to overwrite it?", _
vbExclamation Or vbYesNoCancel, _
"Export") <> vbYes Then Exit Sub
End If

intFile = FreeFile

Open strPath For Output As #intFile

Set dbs = CurrentDb

Set rst = dbs.OpenRecordset("qryExport", dbOpenForwardOnly)

While Not rst.EOF
Print #intFile, Nz(rst!Tel, "")
rst.MoveNext
Wend

MsgBox "Export routine complete", _
vbInformation, "Export"

Exit_Handler:

On Error Resume Next

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Close #intFile

Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub


Ciao Super - Fletcher
I mind giving you so much trouble, I have copied the code that you
have given me, I have modified the interested lines, I have compiled
the program...I press the button, I insert the path and the name of
the file, and this error signals me...

Error No: 3061
non enough parameters. 3
[I hope both corrected the translation]

the file test.txt has been created... but it is empty..

I have modified only these lines

Set rst = dbs.OpenRecordset("query_fuoriorario_cell",
dbOpenForwardOnly)
and
Print #intFile, Nz(rst!cell, "")
query_fuori_orario : it's my export query
cell : it's a field of query_fuori_orario
according to you, as can I resolve this error??

I don't so finally disturb still you...

thx, Fletcher....

where r u from Fletcher?

i live in venice...

have a nice day!

Error 3061 is caused by the query. I don't know what the SQL for
"query_fuoriorario_cell" looks like, but if you had:

SELECT TelNumber
FROM tblNumbers
WHERE SomeDate=[Forms]![frm1].[txtSomeDate]

Then the query would produce this error. It cannot work out this bit
[Forms]![frm1].[txtSomeDate].

The solution to this is to build up the sql string separately - but this can
be quite complicated. If you would like me to have a look at the database
for you then just create a copy, delete any private data and e-mail it to
me. (I''ve copied this message to your e-mail)
Nov 12 '05 #10

cut

Error 3061 is caused by the query. I don't know what the SQL for
"query_fuoriorario_cell" looks like, but if you had:

SELECT TelNumber
FROM tblNumbers
WHERE SomeDate=[Forms]![frm1].[txtSomeDate]

Then the query would produce this error. It cannot work out this bit
[Forms]![frm1].[txtSomeDate].

The solution to this is to build up the sql string separately - but this can
be quite complicated. If you would like me to have a look at the database
for you then just create a copy, delete any private data and e-mail it to
me. (I''ve copied this message to your e-mail)


thanks Fletcher!

I send you a copy of my database

send me your e-mail address in my private box

pa*****************@yahoo.it

you remove SPAM of the address

how can I reciprocate your kind help??

have a good day
Nov 12 '05 #11
Il Mon, 13 Oct 2003 15:38:15 GMT, alessia <al*************@yahoo.it>
ha scritto:

cut

Error 3061 is caused by the query. I don't know what the SQL for
"query_fuoriorario_cell" looks like, but if you had:

SELECT TelNumber
FROM tblNumbers
WHERE SomeDate=[Forms]![frm1].[txtSomeDate]

Then the query would produce this error. It cannot work out this bit
[Forms]![frm1].[txtSomeDate].

The solution to this is to build up the sql string separately - but this can
be quite complicated. If you would like me to have a look at the database
for you then just create a copy, delete any private data and e-mail it to
me. (I''ve copied this message to your e-mail)


thanks Fletcher!

I send you a copy of my database

send me your e-mail address in my private box

pa*****************@yahoo.it

you remove SPAM of the address

how can I reciprocate your kind help??

have a good day

opps....remove NOSPAM of the address...

pa*****************@yahoo.it
have a nice day!
ciao Fletcher!
Nov 12 '05 #12
"alessia" <al*************@yahoo.it> wrote in message
news:un********************************@4ax.com...
Il Mon, 13 Oct 2003 15:38:15 GMT, alessia <al*************@yahoo.it>
ha scritto:

cut

Error 3061 is caused by the query. I don't know what the SQL for
"query_fuoriorario_cell" looks like, but if you had:

SELECT TelNumber
FROM tblNumbers
WHERE SomeDate=[Forms]![frm1].[txtSomeDate]

Then the query would produce this error. It cannot work out this bit
[Forms]![frm1].[txtSomeDate].

The solution to this is to build up the sql string separately - but this canbe quite complicated. If you would like me to have a look at the databasefor you then just create a copy, delete any private data and e-mail it tome. (I''ve copied this message to your e-mail)


thanks Fletcher!

I send you a copy of my database

send me your e-mail address in my private box

pa*****************@yahoo.it

you remove SPAM of the address

how can I reciprocate your kind help??

have a good day

opps....remove NOSPAM of the address...

pa*****************@yahoo.it
have a nice day!
ciao Fletcher!

Sent e-mail
Hope to hear from you soon

Fletcher
Nov 12 '05 #13

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

Similar topics

6
by: Roy Riddex | last post by:
I have a text file which holds data for 30 cars in the following way: CarRegistration CarType CarClass Available I'm trying to display the full contents of this...
1
by: nunYa | last post by:
I am trying to use the DoCmd.TransferText method to export an access table to a Tab Delimited Text File. I have put the code behind the onclick event of a button and keep getting the error...
1
by: Marcelo | last post by:
Hi, I have to do the following, and would like you suggestions on how I could achieve it the best way: I have a text file in the following format: 12345 54321 98765 56789 (3 spaces...
1
by: Hexman | last post by:
Code below ---- I'm trying to save some specific web pages to disk as text files. I searched the Internet and found a basic example which I changed to fit my needs. I tested it out first on a...
2
by: ETOPSA346 | last post by:
Hello, I am trying to write a program that will analyse a text file and do the following: 1. Count the number of characters. 2. Count the number of spaces. 3. Count the number of words....
2
by: garth.waring | last post by:
Hi all I have seen the In Clause used to remotely query a text file done but cannot find the right syntax The example below is for an excel file : SELECT * FROM IN...
3
by: tariq103 | last post by:
I am having trouble with a normally simple function, I am trying to read a text file and output what is in the file: #include <iostream> #include <cmath> #include <iomanip> #include <fstream>...
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...
4
by: CD Tom | last post by:
This is driving me nuts!!! I have a table that one of the columns is set as Double, Fixed, 3 digits. I try and export this to a .txt file for a backup using the docmd.transfertext command but when I...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.