Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2005

Tip: Looking for answers? Try searching our database.

saving to a csv file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
arch - 11 May 2005 14:15 GMT
Hi.  I'm using Access 2000 and I'm having trouble trying to create some vba
code that will allow me to save the data in a query to a csv file (comma
separated text).  I used the acCmdImport command to import the data file
originally.  However, I don't know how to export it (preferably with a gui
to allow the user to enter a filename to save to).  Please provide sample
code.
Alex White MCDBA MCSE - 11 May 2005 14:38 GMT
So you have a listbox or something with a resultset that you want to export
to a text file

dim adoTest as new adodb.recordset
with adoTest
   .open me.lstResults.rowsource, currentproject.connection, adOpenKeyset,
adLockReadOnly
   if .recordcount > 0 then
       Open "c:\MyExported.txt" For Output As #1
       do while not .eof
           write #1, .fields("myFirstField").value,
.fields("mySecondField").value
           .movenext
       loop
       close #1
   end if
end with

one comma seperated file......

Signature

Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

> Hi.  I'm using Access 2000 and I'm having trouble trying to create some
> vba
[quoted text clipped - 3 lines]
> to allow the user to enter a filename to save to).  Please provide sample
> code.
arch - 11 May 2005 15:16 GMT
Thanks.  But what I really wanted was to have a listbox that contains a list
of queries that a user selects, and then presses a button and then he is
walked through selecting a filename to save to etc.  Is there an easier way?
Is there a way to use Runcommand, like with the import wizard, or something
similar?

> So you have a listbox or something with a resultset that you want to export
> to a text file
[quoted text clipped - 29 lines]
> > to allow the user to enter a filename to save to).  Please provide sample
> > code.
Alex White MCDBA MCSE - 11 May 2005 15:34 GMT
Create all the queries with a specific prefix e.g. queryMyUsers1,
queryMyUsers2

use the following as the rowsource for the listbox

SELECT Right(Name,Len(name)-5) AS Expr1
FROM MSysObjects
WHERE (((MSysObjects.Name) Like "query*"))
ORDER BY MSysObjects.Name;

if you called the listbox lstQueries

Private Sub lstQueries_DblClick(Cancel As Integer)
   dim adoTest as new adodb.recordset
   with adoTest
       .open "query" & me.lstQueries.column(0),
currentproject.connection,adOpenKeyset,adLockReadOnly
       if .recordcount > 0 then
           Open "c:\MyExported.txt" For Output As #1
           do while not .eof
                   write #1,
.fields("myFirstField").value,.fields("mySecondField").value
                   .movenext
           loop
           close #1
   end if
end with

this code could be modified to allow for multi-selection, I never use the
import wizard as it does not give me the flexability I need most of the
time.

open a file,

http://support.microsoft.com/default.aspx?scid=kb;en-us;303066

save file dialog

http://vbnet.mvps.org/index.html?code/comdlg/filesavedlg.htm

give it ago, hope it is closer to what you need!

Signature

Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

> Thanks.  But what I really wanted was to have a listbox that contains a
> list
[quoted text clipped - 44 lines]
> sample
>> > code.
arch - 11 May 2005 23:46 GMT
If I wanted to invoke the export wizard on a query, how would I do that?

> Create all the queries with a specific prefix e.g. queryMyUsers1,
> queryMyUsers2
[quoted text clipped - 92 lines]
> > sample
> >> > code.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.