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!!!
1 10305
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. -
Private Sub cmdExport_Click()
-
On Error GoTo ErrHandler
-
Dim rs As ADODB.Recordset
-
Dim strSql As String
-
Const SW_SHOWNORMAL = 1
-
-
'Clear the text file
-
Open ExportPath For Output As #1
-
Print #1, ""
-
Close #1
-
If lstPersonnel.SelCount = 0 Then 'Get all records
-
iRow = 1
-
For i = 0 To lstPersonnel.ListCount - 1
-
-
strSql = "EXEC spCFD_CJAC_Export @dStartDate = '" & dtpStartDate.Value & _
-
"', @dEndDate = '" & dtpEndDate.Value & "', @iCityIDNum = " _
-
& lstPersonnel.ItemData(i)
-
'MsgBox strSql
-
Set rs = GetADORSP(strSql)
-
Open ExportPath For Append As #1
-
Do While Not rs.eof
-
Print #1, rs.GetString(, , "|", vbCrLf, "");
-
-
Loop
-
Close #1
-
Set rs = Nothing
-
Next i
-
Else 'Get only the selected personnel data
-
-
iRow = 1
-
For i = 0 To lstPersonnel.ListCount - 1
-
-
If lstPersonnel.Selected(i) = True Then
-
-
strSql = "EXEC spCFD_CJAC_Export @dStartDate = '" & dtpStartDate.Value & _
-
"', @dEndDate = '" & dtpEndDate.Value & "', @iCityIDNum = " _
-
& lstPersonnel.ItemData(i)
-
Set rs = GetADORSP(strSql)
-
Open ExportPath For Append As #1
-
-
Do While Not rs.eof
-
Print #1, rs.GetString(, , "|", vbCrLf, "");
-
-
Loop
-
Close #1
-
End If
-
Set rs = Nothing
-
-
Next i
-
-
-
End If
-
Set rs = Nothing
-
'Check to see if they want to review the text file before sending it out.
-
If MsgBox("Would you like to review the data file to be sent?", vbYesNo, "Attention") = vbYes Then
-
Call ShellExecute(Me.hWnd, "open", ExportPath, "", 0, SW_SHOWNORMAL)
-
End If
-
Exit Sub
-
ErrHandler:
-
MsgBox "Error exporting data. Error # " & Err.Number & ", " & Err.Description, vbOKOnly, "Error"
-
Set rs = Nothing
-
Close #1
-
End Sub
-
If you need more help, let the group know.
Sign in to post your reply or Sign up for a free account.
Similar topics
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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: 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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |