473,513 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on exporting records to csv file

3 New Member
I have the following code that takes form data from a picklist and uses the input values to query an access database. Currently everything works, but it writes the results to the same page when submit is selected. I would like (if possible) to write the results to a csv file that could be saved on the users computer. Is this possible? If so can some one give me a little help with this ?
Here is the code that I have.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>ECVS Report Generator</title>
  3. <head>
  4.  
  5. <script>
  6. function clearForms()
  7. {
  8. var i;
  9. for (i = 0; (i < document.forms.length); i++) {
  10. document.forms[i].reset();
  11. }
  12. }
  13. </script>
  14. </head>
  15. <body bgcolor="#FFFFFF" onLoad="clearForms()" onUnload="clearForms()" background="http://bytes.com/images/background1.png">
  16. <%
  17.  
  18.  
  19.  
  20. u_input1 = trim(request.form("u_input1"))
  21. u_input2 = trim(request.form("u_input2"))
  22. u_input3 = trim(request.form("u_input3"))
  23.  
  24. u_field1=request.form("u_field1")
  25. u_field2=request.form("u_field2")
  26. u_field3=request.form("u_field3")
  27.  
  28. if u_input1 <> "" then
  29.  
  30. accessdb="custmast" '
  31. table_name="customermast"
  32. cn="driver={microsoft access driver (*.mdb)};"
  33. cn=cn & "dbq=" & server.mappath(accessdb)
  34. set rs = server.createobject("ADODB.Recordset")
  35. sql = "select * from "& table_name &" where " & u_field1 & " like '%%" & u_input1 & "%%' And " & u_field2 & " like '%%" & u_input2 & "%%' And " & u_field3 &" like '%%" & u_input3 & "%%' "
  36.  
  37.  
  38. rs.Open sql, cn
  39.  
  40. if rs.eof or rs.bof then
  41. response.write "No results found..."
  42. observations=0
  43. else
  44. observations=1
  45. end if 'end check for observations
  46. end if 'end check for user input
  47. %>
  48.  
  49.  
  50.  
  51.  
  52. <%
  53. if observations > 0 then %>
  54.  
  55. <!--- This is where it specifies what to do if there are observations ---->
  56. <table>
  57. <tr>
  58. <% 'Write the field names
  59. for each table_element in rs.fields
  60. %>
  61.  
  62. <td><b><%= table_element.name%></B></TD><%
  63. next %>
  64. </tr>
  65. <tr>
  66. <% 'Write the values
  67. rs.movefirst
  68. do while not rs.eof
  69. for each cell in rs.fields %>
  70. <td><%= cell.value %></td><%
  71. next %>
  72. </tr>
  73. <% rs.movenext
  74. loop %>
  75. </table>
  76.  
  77.  
  78. <% end if 'end of check of obs for display%>
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. <br>
  90. <br>
  91. <br>
  92. <br>
  93. <br>
  94. <br>
  95. <br>
  96. <table align="center">
  97. <tr>
  98. <td>
  99. <form action ="" method="post">
  100.  
  101. <select name="u_field1" size="1">
  102. <option <% ' write out all the search fields and select
  103. if u_field1 = "state" or u_field1 = "" then
  104. response.write "selected "
  105. end if
  106. %>value="AccountNumber">Account Number</option>
  107. <option <%
  108. if u_field1 = "AccountName" then
  109. response.write "selected "
  110. end if
  111. %>value="AccountName">Account Name</option>
  112. <option <%
  113. if u_field1 = "SalesVolume" then
  114. response.write "selected "
  115. end if
  116. %>value="SalesVolume">Sales Volume</option>
  117. <option <%
  118. if u_field1 = "BusinessUnit" then
  119. response.write "selected "
  120. end if
  121. %>value="BusinessUnit">Business Unit</option><br>
  122. <option <%
  123. if u_field1 = "SalesRegion" then
  124. response.write "selected "
  125. end if
  126. %>value="SalesRegion">Sales Region</option>
  127. <option <%
  128. if u_field1 = "State" then
  129. response.write "selected "
  130. end if
  131. %>value="state">State</option>
  132. <option <%
  133. if u_field1 = "PriceGroup" then
  134. response.write "selected "
  135. end if
  136. %>value="PriceGroup">Price Group</option>
  137. <option <%
  138. if u_field1 = "DealerType" then
  139. response.write "selected "
  140. end if
  141. %>value="DealerType">Dealer Type</option>
  142. <option <%
  143. if u_field1 = "BillingType" then
  144. response.write "selected "
  145. end if
  146. %>value="BillingType">Address Type</option>
  147. <option <%
  148. if u_field1 = "StartDate" then
  149. response.write "selected "
  150. end if
  151. %>value="StartDate">Start Date</option>
  152. <option <%
  153. if u_field1 = "AccountRep" then
  154. response.write "selected "
  155. end if
  156. %>value="AccountRep">Account Rep</option>
  157.  
  158. </select>
  159. &nbsp; = &nbsp;
  160. <input type="text" name="u_input1" value="<%= u_input1 %>">
  161. <br><br>
  162. AND
  163. <br><br>
  164.  
  165. <select name="u_field2" size="1">
  166. <option <% ' write out all the search fields and select
  167. if u_field2 = "state" or u_field2 = "" then
  168. response.write "selected "
  169. end if
  170. %>value="AccountNumber">Account Number</option>
  171. <option <%
  172. if u_field2 = "AccountName" then
  173. response.write "selected "
  174. end if
  175. %>value="AccountName">Account Name</option>
  176. <option <%
  177. if u_field2 = "SalesVolume" then
  178. response.write "selected "
  179. end if
  180. %>value="SalesVolume">Sales Volume</option>
  181. <option <%
  182. if u_field2 = "BusinessUnit" then
  183. response.write "selected "
  184. end if
  185. %>value="BusinessUnit">Business Unit</option>
  186. <option <%
  187. if u_field2 = "SalesRegion" then
  188. response.write "selected "
  189. end if
  190. %>value="SalesRegion">Sales Region</option>
  191. <option <%
  192. if u_field2 = "State" then
  193. response.write "selected "
  194. end if
  195. %>value="state">State</option>
  196. <option <%
  197. if u_field2 = "PriceGroup" then
  198. response.write "selected "
  199. end if
  200. %>value="PriceGroup">Price Group</option>
  201. <option <%
  202. if u_field2 = "DealerType" then
  203. response.write "selected "
  204. end if
  205. %>value="DealerType">Dealer Type</option>
  206. <option <%
  207. if u_field2 = "BillingType" then
  208. response.write "selected "
  209. end if
  210. %>value="BillingType">Address Type</option>
  211. <option <%
  212. if u_field2 = "StartDate" then
  213. response.write "selected "
  214. end if
  215. %>value="StartDate">Start Date</option>
  216. <option <%
  217. if u_field2 = "AccountRep" then
  218. response.write "selected "
  219. end if
  220. %>value="AccountRep">Account Rep</option>
  221. </select>
  222.  
  223. &nbsp; = &nbsp;
  224.  
  225. <input type="text" name="u_input2" value="<%= u_input2 %>">
  226. <br><br>
  227. AND
  228. <br><br>
  229.  
  230. <select name="u_field3" size="1">
  231. <option <% ' write out all the search fields and select
  232. if u_field3 = "state" or u_field3 = "" then
  233. response.write "selected "
  234. end if
  235. %>value="AccountNumber">Account Number</option>
  236. <option <%
  237. if u_field3 = "AccountName" then
  238. response.write "selected "
  239. end if
  240. %>value="AccountName">Account Name</option>
  241. <option <%
  242. if u_field3 = "SalesVolume" then
  243. response.write "selected "
  244. end if
  245. %>value="SalesVolume">Sales Volume</option>
  246. <option <%
  247. if u_field3 = "BusinessUnit" then
  248. response.write "selected "
  249. end if
  250. %>value="BusinessUnit">Business Unit</option>
  251. <option <%
  252. if u_field3 = "SalesRegion" then
  253. response.write "selected "
  254. end if
  255. %>value="SalesRegion">Sales Region</option>
  256. <option <%
  257. if u_field3 = "State" then
  258. response.write "selected "
  259. end if
  260. %>value="state">State</option>
  261. <option <%
  262. if u_field3 = "PriceGroup" then
  263. response.write "selected "
  264. end if
  265. %>value="PriceGroup">Price Group</option>
  266. <option <%
  267. if u_field3 = "DealerType" then
  268. response.write "selected "
  269. end if
  270. %>value="DealerType">Dealer Type</option>
  271. <option <%
  272. if u_field3 = "BillingType" then
  273. response.write "selected "
  274. end if
  275. %>value="BillingType">Address Type</option>
  276. <option <%
  277. if u_field3 = "StartDate" then
  278. response.write "selected "
  279. end if
  280. %>value="StartDate">Start Date</option>
  281. <option <%
  282. if u_field3 = "AccountRep" then
  283. response.write "selected "
  284. end if
  285. %>value="AccountRep">Account Rep</option>
  286. </select>
  287. &nbsp; = &nbsp;
  288.  
  289. <input type="text" name="u_input3" value="<%= u_input3 %>">
  290. <br><br>
  291. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
  292. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  293. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  294.  
  295. <input type="submit" value="Submit">
  296. </form>
  297. </td>
  298. </tr>
  299. </table>
  300.  
  301. <p>&nbsp</p>
Sep 18 '09 #1
3 2028
jhardman
3,406 Recognized Expert Specialist
It is possible to return a CSV file rather than an HTML page after the user hits submit. Whether the user saves the file must be left to him. Let me know if that's good enough for you, if it is, I will try to help with the code.

Jared
Sep 18 '09 #2
jrnowlan
3 New Member
Thanks for the response. That would be great. I was hoping to pop up a dialog box for the user to select save file or something similar to downloading a file from a site. Any help would be greatly appreciated !!
Sep 18 '09 #3
jhardman
3,406 Recognized Expert Specialist
@jrnowlan
OK, a CSV file is just a text file that might look like this:
Expand|Select|Wrap|Line Numbers
  1. columnA,columnB,id
  2. val1a,val1b,1
  3. val2a,val2b,2
So the first step is to be able to put all of the data you have in a string formatted as a CSV file. Can you do that yet?

Jared
Sep 19 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1962
by: Angel Cat | last post by:
I'm exporting a large file from a large Production database (SQL). Users are currently updating and inserting new records. Does the export take a snapshot of the data when it starts ? or will...
5
11672
by: jsudo | last post by:
I have a Access database with a large amount of records (close to 500,000) that I would like to export to Excel. I found out that Excel has the capability of of about 65,000 rows so I know I...
4
15802
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
0
3323
by: Otis Hunter | last post by:
I have been fighting with this for days and your expert help is needed! Below is the code I am executing which results with "Object doesn't support this property or method". The error is occuring...
6
4962
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
2
2391
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
21
6188
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the...
2
1797
by: accessvbanewbie | last post by:
I keep getting an error stating OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET. This error just recently began to happen. I am exporting some records to excel into a preformatted report. The...
1
4891
by: Marty Klunk | last post by:
I have an Access97 data base where we are exporting records out to a text file that is then sent to a customer via EDI transmission. The problem I am having is that during the export process access...
2
2049
by: jjwiet | last post by:
Hello, I use access 2003 and attempting to export/copy records between two access databases (almost identical) with multiple tables (both databases having the same relations between the tables)....
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7535
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
7098
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
7523
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
5683
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
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.