I have a sql statement:
"SELECT Field1,field2 FROM table WHERE field1="[FORM]![PARAMETER]"
I need to export this to a CSV file with header information.
How can I do this?
I've tried the below function "save_data()", but I get a "expression
expected 1 error", I think b/c text transfer does not support
parameters during export. In addition, no header information apppears
even though the specifications are set to.
Think I need to pass the parameter in the function, use the SQL to make
a recordset that then gets made into a CSV file. But I need help. I
don't know where to start.
Thanks
**************************************************
Function savedata()
On Error GoTo Err_export
Dim AString As String
Dim query As String
'already made query
queryname = "myquery"
AString = "export_data_"
DoCmd.TransferText acExportDelim, "specification1", queryname,
"C:\Temp\" & AString & Format(Date, "YYYY_MMDD") & ".csv"
Exit_export:
Exit Function
Err_export:
MsgBox Err.Description
Resume Exit_export
End Function 8 19703
Albert Kallal has code that does this. He's an MVP, so you can get his
web site address from www.mvps.org/access
or you could roll one yourself using Freefile and then print
statements... kinda tedious, though. but you could just loop through
the records of your query and then inside that loop through the fields
and output that to csv... tediuos, but not terribly hard.
HTH,
Pieter
Can you please give me the exact link, I can not seem to find the link.
In addition, I'm not really sure how to use Freefile, do you have
example code?
Thanks!
stop...@hotmail.com wrote: Can you please give me the exact link, I can not seem to find the
link. In addition, I'm not really sure how to use Freefile, do you have example code?
Thanks!
Oh, now I feel stupid. Tried to go to his website, and it appears to
be down... (Has anybody seen Albert around anywhere? I haven't seen
his posts in a while...) but, I do know for one thing, that he has
code that does all this stuff for you. Pass a table or query or (?)
SQL statement, and it outputs to CSV for you... It's all packaged into
a class so you can import it and use it.
Now to actually *find* the thing!
Double dumb, I am. Is the message not "Too few parameters, expected
n"? If so, read this article. http://www.mvps.org/access/queries/qry0013.htm
See if that doesn't solve your problem first... then if more drastic
measures are called for, we'll go from there. No sense in confusing
you further now if it's not necessary.
Pieter
(Hey, this village is *taken*!!!) pi********@hotmail.com wrote: Oh, now I feel stupid. Tried to go to his website, and it appears to be down... (Has anybody seen Albert around anywhere? I haven't seen his posts in a while...) but, I do know for one thing, that he has code that does all this stuff for you. Pass a table or query or (?) SQL statement, and it outputs to CSV for you... It's all packaged
into a class so you can import it and use it.
Now to actually *find* the thing!
Check out http://groups-beta.google.com/group/...d76ba87ff7fc0b
James A. Fortune st*****@hotmail.com wrote: I have a sql statement:
"SELECT Field1,field2 FROM table WHERE field1="[FORM]![PARAMETER]"
I need to export this to a CSV file with header information.
How can I do this?
I've tried the below function "save_data()", but I get a "expression expected 1 error", I think b/c text transfer does not support parameters during export. In addition, no header information apppears even though the specifications are set to.
Think I need to pass the parameter in the function, use the SQL to make a recordset that then gets made into a CSV file. But I need help. I don't know where to start.
Thanks ************************************************* * Function savedata()
On Error GoTo Err_export
Dim AString As String Dim query As String
'already made query
queryname = "myquery"
AString = "export_data_"
DoCmd.TransferText acExportDelim, "specification1", queryname, "C:\Temp\" & AString & Format(Date, "YYYY_MMDD") & ".csv"
Exit_export: Exit Function
Err_export: MsgBox Err.Description Resume Exit_export
End Function
This
"SELECT Field1,field2 FROM table WHERE field1="[FORM]![PARAMETER]"
should look like... if Field1 and parameter are numeric
"SELECT Field1, field2 FROM table WHERE field1=" & [FORM]![PARAMETER] &";"
or like this if text
"SELECT Field1, field2 FROM table WHERE field1='" & [FORM]![PARAMETER] & "';"
--
Ronald W. Roberts
Roberts Communication rw*@robcom.com
Thanks for the page, but I still can not find the item you are
referring to.
Any more help is apprecaited.
I read this article, but I think the "&" is there when using it within,
VBA, is this correct?
I'm trying to run the SQL direct for the query itself. The issue is
when I call the query direct form within Access, the query works great.
But when I use VBA's docmd.transfertext,
I get the error, I read somewhere that the transfer text feature can
not handle parameters. So I thought maybe using VBA to loop though the
recordset and build the CSV file, line by line would work, only I don't
know how to code it, as I've not written to a text file with VBA.
Thanks
I apprecaite all the help This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kevin P |
last post by:
Hi News Group,
In an application written in C# and VS.Net using Dotnet Framework 1.1.4322
on XP and Win 2000 machines, we randomly get the error "Failed to load
resources from resource file....
|
by: Preference |
last post by:
Hello,
I am developing a .NET application in managed C++. Until now we have
executed without problems in a lot of different computers. But a few days ago
we detect a problem in some laptops. In...
|
by: donis |
last post by:
Hi i am doing a project for making a hotel management system in
Microsoft Access
I wantto make a hotel with 20 rooms
5 = suite
5= double
5= duobleo view
5 - rooms at single
4 types of room...
|
by: Neo Geshel |
last post by:
I have the two subs:
Sub UniqueHits()
Dim StrSQLQuery As String
Dim ObjAdapter as New OleDbDataAdapter()
Dim ObjDataSet as DataSet
StrSQLQuery = "SELECT * FROM Browser WHERE IsUnique = True"...
|
by: Nicolas |
last post by:
Hello
I can already export my datagrid (not dataset because my datagrid has
rowfilters) to excel and word. But I can't seem to manage it to write it
to plain/text . Anyone has advise ? ...
|
by: Martin Ho |
last post by:
Can someone help me with this please? I wasn't very clear in my old
post.
I have a program to copy files from one location to another, now I
want to copy only those files which were created on...
|
by: Vijaya P Krishna |
last post by:
Hi,
I have a .NET Windows Forms application, written in VB.NET and C#.
I am opening a URL from the application using Process.Start(). The URL
points to a java servlet running on apache-tomcat....
|
by: JayDawg |
last post by:
If anyone is willing to provide some consulting pro-bono, or for a very
small charge I would really love the asistance.
If anyone can fix my problem here online that would be even better.
Here...
|
by: shapper |
last post by:
Hello,
In have a class inside a compiled DLL where I have the following code:
' Create site map XML document
Dim siteMap As XmlDocument = New XmlDocument
' Load site map XML document from...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |