Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export to Text file(s)

Status
Not open for further replies.

djfeldspiff

Programmer
Apr 26, 2001
16
US
Greetings everyone,

I'm submitting a piece of code for your review. Here's what I'm trying to do.

I have a dB set up to export data from a table to a text file used for printing calling cards. One of our clients has multilpe cards that we fulfill. I'd like to be able to export separate text files based on the "Card Type" the customer requested, each file having it's own file name.

Ex: 10 customers, 8 card type A, 2 card type B. One file of all customers who requested card type A (8 records), a separate file of customers who requested card type B (2 records.

When the code runs (behind a command box as an OnClick event) I get two files with individual file names, but each file contains all data (To reference my example, I would end up with two files, each file with 10 records regardless of the card type requested).

Where am I going wrong? Thanks for your assistance!!

Private Sub StartExportButton_Click()

Dim rstCCIN As Recordset
Dim rst As Recordset
Dim intCounter As Integer
Dim CCFilename As String

' Open Calling Card record sets
Set rstCCIN = CurrentDb.OpenRecordset("CCIN")
Set rst = CurrentDb.OpenRecordset("CCIN CARDTYPE")

' Display message to enter file name if left blank
If IsNull(Me.File1) Then
MsgBox "ERROR: You must enter the filename.", vbExclamation
GoTo StartExportBtn_Exit
Else
' View and export Calling Card data
rst.MoveLast
rst.MoveFirst
Do Until rst.EOF
For intCounter = 1 To rst.RecordCount
CCFilename = "C:\" & rst!TYPE & Me!File1
DoCmd.TransferText acExportFixed, "Export Specification", "CCIN CARDTYPE", CCFilename
rst.MoveNext
Next
Loop
rst.Close

' Display message that export is complete
MsgBox "Export Completed.", vbInformation, "Export Status"

End If

StartExportBtn_Exit:
Exit Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top