dao function alteration

robhargreaves

Registered User.
Local time
Today, 00:39
Joined
Mar 4, 2005
Messages
11
Hi I need to output myself a csv file of all information since the procedure was last run (i.e - any new data since the last export to csv was done)

I have created an unlinked table to just contain a single value in a single row holding the date. For the first ever press because there will be no date pre entered i will have to say if null export all data in the csv, this would then have to be updated in the code but I dont know how to write to it when an event happens.

I know what data I need to export and I have a query which will collect this information for us. I dont know how to specify the qry name although my querie is called qryexportcsv

This is the code I have found on this site which is similar.

dim AString as string
Dim rst as dao.recordset '
Set rst = currentdb.openrecordset("qryexportcsv")
aString = rst![YourField] ' I dont know what this line does?????
set rst = nothing
docmd.TransferText acexportdelim,"SpecName","TableName","C:\Test" & AString & Format(date,"YYYYMMDD") & ".csv"

I think the filename is how I want it (20051212.csv????) but I need the location to always be the desktop can you help me do this?

Thanks
 
Last edited:
This is my new code I need it to give itself the name of the current date.csv It already gets its path to the desktop so that will be just right

Dim path As String
Dim wShell As Object 'New wshShell
Set wShell = CreateObject("WScript.Shell")
path = wShell.SpecialFolders("Desktop")
Set wShell = Nothing
DoCmd.TransferText acExportDelim, , "qryexportcsv", path + "\export.csv", True
 
Last edited:
robhargreaves said:
aString = rst![YourField] ' I dont know what this line does?????

The command returns a value for the field in ur table.
For instance if you had a table called PEOPLE:

Code:
Name    Age
John     10
Sam      11
Deb      12
Mike     13
Sue      14
and your query was SELECT * FROM PEOPLE

after opening your recodset, calling rst!Age would return the value for whatever record it was on. If it was on Deb, it'd return "12"; if it was on Sue, it'd return "14"



docmd.TransferText acexportdelim,"SpecName","TableName","C:\Test" & AString & Format(date,"YYYYMMDD") & ".csv"
The C:\Test is where you set the desktop.

Try:
docmd.TransferText acexportdelim,"SpecName","TableName","C:\Documents and Settings\" & Environ("UserName") & "\Desktop\" & ASTring & Format(date,"YYYYMMDD") & ".csv"
 
Last edited:

Users who are viewing this thread

Back
Top Bottom