Below is code I am working with. I would like to change the code to work with a command button & export the current record on a form to a text file (with header information) INSTEAD of exporting a query to a text file. Can this be done? I sure it can, just not sure how to construct it....
Thanks in advance!!
jw
Sub ExportTextFile()
On Error GoTo ExportTextFile_Err
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim Directory As String
Dim MyString As String, strSQL As String
Dim strDS As String
Set cnn = CurrentProject.Connection
strDS = cnn.Properties("data source")
Directory = (Mid(strDS, 1, Len(strDS) - Len(Dir(strDS))))
Open Directory & "\Timeline.txt" For Output As #1
rst.Open "qryExportFormatted", cnn, adOpenForwardOnly, adLockReadOnly
Print #1, "This is where header information would go if needed"
rst.MoveFirst
Do While Not rst.EOF
MyString = rst!formattedNumber & _
rst!FormattedAmount & _
rst!FormattedCheckdate & _
rst!FormattedAcctNbr & _
rst!Fill_Field & rst!test
Print #1, MyString
rst.MoveNext
Loop
ExportTextFile_Exit:
' Close text file.
Close #1
rst.Close
Set cnn = Nothing
Exit Sub
ExportTextFile_Err:
MsgBox Err.Description
Resume ExportTextFile_Exit
End Sub
Thanks in advance!!
jw
Sub ExportTextFile()
On Error GoTo ExportTextFile_Err
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim Directory As String
Dim MyString As String, strSQL As String
Dim strDS As String
Set cnn = CurrentProject.Connection
strDS = cnn.Properties("data source")
Directory = (Mid(strDS, 1, Len(strDS) - Len(Dir(strDS))))
Open Directory & "\Timeline.txt" For Output As #1
rst.Open "qryExportFormatted", cnn, adOpenForwardOnly, adLockReadOnly
Print #1, "This is where header information would go if needed"
rst.MoveFirst
Do While Not rst.EOF
MyString = rst!formattedNumber & _
rst!FormattedAmount & _
rst!FormattedCheckdate & _
rst!FormattedAcctNbr & _
rst!Fill_Field & rst!test
Print #1, MyString
rst.MoveNext
Loop
ExportTextFile_Exit:
' Close text file.
Close #1
rst.Close
Set cnn = Nothing
Exit Sub
ExportTextFile_Err:
MsgBox Err.Description
Resume ExportTextFile_Exit
End Sub