Article View: pl.comp.bazy-danych.msaccess
Article #137308Re: export kwerendy do pliku csv
From: MaciejF
Date: Tue, 22 Nov 2016 08:33
Date: Tue, 22 Nov 2016 08:33
59 lines
2729 bytes
2729 bytes
Witaj,
Pomiń wywoływanie obiektu Excel.
Proponuję użyć procedurkę VBA:
"
Public Sub exportQuery(exportSQL As String)
Dim db As DAO.Database, qd As DAO.QueryDef
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogSaveAs)
Set db = CurrentDb
'Check to see if querydef exists
For i = 0 To (db.QueryDefs.Count - 1)
If db.QueryDefs(i).Name = "tmpExport" Then
db.QueryDefs.Delete ("tmpExport")
Exit For
End If
Next i
Set qd = db.CreateQueryDef("tmpExport", exportSQL)
'Set intial filename
fd.InitialFileName = "export_" & Format(Date, "mmddyyy") & ".csv"
If fd.show = True Then
If Format(fd.SelectedItems(1)) <> vbNullString Then
DoCmd.TransferText acExportDelim, , "tmpExport", fd.SelectedItems(1), False
End If
End If
'Cleanup
db.QueryDefs.Delete "tmpExport"
db.Close
Set db = Nothing
Set qd = Nothing
Set fd = Nothing
End Sub
"
Wywoływana pod przyciskiem:
Public Sub someButton_Click()
Dim queryStr as String
'Store Query Here:
queryStr = "SELECT * FROM..."
Call exportQuery(queryStr)
End Sub
źródło:
http://stackoverflow.com/questions/14700192/vba-docmd-transfertext-exporting-query-to-csv-with-user-defined-file-path
MF
Technical Details
Message-ID:
<52bd68b0-2bdb-49ca-b2e8-e489c65cc9ea@googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!w132no1570235ita.0!news-out.google.com!k2ni3662itb.0!nntp.google.com!w132no1570228ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mailReferences:
<39d994b6-e28e-4fc2-a084-f06f776fd643@googlegroups.com>Show Full Headers
Complete Article Headers
X-Received: by 10.99.108.8 with SMTP id h8mr6940404pgc.50.1479803632818; Tue, 22 Nov 2016 00:33:52 -0800 (PST) X-Received: by 10.157.15.143 with SMTP id d15mr1065217otd.2.1479803632762; Tue, 22 Nov 2016 00:33:52 -0800 (PST) Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!w132no1570235ita.0!news-out.google.com!k2ni3662itb.0!nntp.google.com!w132no1570228ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: pl.comp.bazy-danych.msaccess Date: Tue, 22 Nov 2016 00:33:52 -0800 (PST) In-Reply-To: <39d994b6-e28e-4fc2-a084-f06f776fd643@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=213.241.94.194; posting-account=kc7ZIQoAAAB5PkdJgxjq1dd8jnBK4MVp NNTP-Posting-Host: 213.241.94.194 References: <39d994b6-e28e-4fc2-a084-f06f776fd643@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <52bd68b0-2bdb-49ca-b2e8-e489c65cc9ea@googlegroups.com> Subject: Re: export kwerendy do pliku csv From: MaciejF <maciejfr@onet.pl> Injection-Date: Tue, 22 Nov 2016 08:33:52 +0000 Lines: 62 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit