473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Export Access Tables to "|" delimited text files

3
Help!!! Am extremely new to VBA. Want to set up code behind a button that will prompt the user for a table name(source of data) and file name(end result of export) and then export the data into a pipe delimited text file.

Appreciate any help!!!
Jun 5 '06 #1
1 10305
CaptainD
135 100+
This code works in VB, you should be able to adapt it to Access VBA
Notes: Exportpath is a variable that holds the drive, folder and file name.
(C:\ExportFolder\ExportFile.txt)
GetADORSP is a funtion that passes back the recordset, you just need to great a recordset how ever your program is doing it.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdExport_Click()
  2. On Error GoTo ErrHandler
  3. Dim rs As ADODB.Recordset
  4. Dim strSql As String
  5. Const SW_SHOWNORMAL = 1
  6.  
  7. 'Clear the text file
  8. Open ExportPath For Output As #1
  9. Print #1, ""
  10. Close #1
  11. If lstPersonnel.SelCount = 0 Then 'Get all records
  12.     iRow = 1
  13.     For i = 0 To lstPersonnel.ListCount - 1
  14.  
  15.         strSql = "EXEC spCFD_CJAC_Export @dStartDate = '" & dtpStartDate.Value & _
  16.         "', @dEndDate = '" & dtpEndDate.Value & "', @iCityIDNum = " _
  17.         & lstPersonnel.ItemData(i)
  18.         'MsgBox strSql
  19.         Set rs = GetADORSP(strSql)
  20.     Open ExportPath For Append As #1
  21.     Do While Not rs.eof
  22.         Print #1, rs.GetString(, , "|", vbCrLf, "");
  23.  
  24.     Loop
  25.     Close #1
  26.     Set rs = Nothing
  27.     Next i
  28. Else 'Get only the selected personnel data
  29.  
  30.         iRow = 1
  31.         For i = 0 To lstPersonnel.ListCount - 1
  32.  
  33.             If lstPersonnel.Selected(i) = True Then
  34.  
  35.                 strSql = "EXEC spCFD_CJAC_Export @dStartDate = '" & dtpStartDate.Value & _
  36.                 "', @dEndDate = '" & dtpEndDate.Value & "', @iCityIDNum = " _
  37.                 & lstPersonnel.ItemData(i)
  38.                 Set rs = GetADORSP(strSql)
  39.                 Open ExportPath For Append As #1
  40.  
  41.                 Do While Not rs.eof
  42.                     Print #1, rs.GetString(, , "|", vbCrLf, "");
  43.  
  44.                 Loop
  45.                     Close #1
  46.             End If
  47.                 Set rs = Nothing
  48.  
  49.         Next i
  50.  
  51.  
  52. End If
  53. Set rs = Nothing
  54. 'Check to see if they want to review the text file before sending it out.
  55. If MsgBox("Would you like to review the data file to be sent?", vbYesNo, "Attention") = vbYes Then
  56.     Call ShellExecute(Me.hWnd, "open", ExportPath, "", 0, SW_SHOWNORMAL)
  57. End If
  58. Exit Sub
  59. ErrHandler:
  60.     MsgBox "Error exporting data. Error # " & Err.Number & ", " & Err.Description, vbOKOnly, "Error"
  61. Set rs = Nothing
  62. Close #1
  63. End Sub
  64.  
If you need more help, let the group know.
Jun 5 '06 #2

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

Similar topics

0
by: Melanie | last post by:
Hi For my company I work for I have to read and process files from Excel, Access or MS SQL. This way is no poblem. I use the JDBC/ODBC bridge to make a delimited file (*.csv) and work with that....
0
by: Shawn Mehaffie | last post by:
I have the following class that I've wirtten to take a Dataset and automatically export it to either XML, ASCII or Tab delimited file. The reason I wrote it they way I did was that I don't want to...
5
by: Tim Eliot | last post by:
Just wondering if anyone has hit the following issue and how you might have sorted it out. I am using the command: DoCmd.TransferText acExportMerge, , stDataSource, stFileName, True after...
0
by: Shawn Mehaffie | last post by:
I have the following class that I've wirtten to take a Dataset and automatically export it to either XML, ASCII or Tab delimited file. The reason I wrote it they way I did was that I don't want to...
1
by: Stella | last post by:
Help!!! Am extremely new to VBA. Want to set up code behind a button that will prompt the user for a table name(source of data) and file name(end result of export) and then export the data into a...
3
by: excyauseme | last post by:
Hi guys! Do you know what is the best way to export a text file, this one is a log file that is already comma delimited thru a module run by my access database, to an excel spreadsheet? I need to...
7
by: mattc66 via AccessMonster.com | last post by:
I need to create an EDI 850 Record Set. The EDI 850 Record set I am creating consists of 2-5 seperate tables all linked by the CustomerID and CustomerPO. Tables - tblOrder - >Link CustomerID...
3
by: azzi2000 | last post by:
This should be rather simple. I have a query using different link tables and 2 parameters. The query works perfect. However I need to export or save the result in an Access table in order to...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.