Hi there, I am having an issue with the below code. The debug error keeps highliting the "Print #fFile, strString" section of the code, but i can't figure out what's wrong with it. All I'm attempting is to create a recordset with a SQL string and export it as a text file..
can you help?? thanks. a million.
Function testme()
Dim fFile As Long
Dim strFile As String
Dim strString As String
Dim Rs As Recordset
Dim RsSql As String
fFile = FreeFile
'Nominate the output text file path and name
strFile = "C:\Documents and Settings\eklinkbe\desktop\testme2.Txt"
'***You may want to put a check in here to test if the file
'***already exists, and as the user if they want to overwrite it first
'***Use the Kill strFile to delete it first
'Create a snapshot of data from your table with the desired fields and data
RsSql = "Select Messages, Minutes, Charges From 201205Summary"
'Open the recordset and test for EOF
Set Rs = CurrentDb.OpenRecordset(RsSql)
If Not Rs.EOF And Not Rs.BOF Then
Open strFile For Output As #fFile
Do Until Rs.EOF
'Loop across all fields in recordset delimiting them with a tab key
For i = 0 To Rs.Fields.Count - 1
strString = strString & Rs(i) & vbTab
Next
'Output the resulting string to the text file
Print #fFile, strString
'Reset the string to empty for the next record
strString = ""
'Move to the next record in the recordset
Rs.MoveNext
Loop
'Close the recordset and the text file
Rs.Close
Close #fFile
End If
'Destroy the instance of the recordset from memory
Set Rs = Nothing
End Function
can you help?? thanks. a million.
Function testme()
Dim fFile As Long
Dim strFile As String
Dim strString As String
Dim Rs As Recordset
Dim RsSql As String
fFile = FreeFile
'Nominate the output text file path and name
strFile = "C:\Documents and Settings\eklinkbe\desktop\testme2.Txt"
'***You may want to put a check in here to test if the file
'***already exists, and as the user if they want to overwrite it first
'***Use the Kill strFile to delete it first
'Create a snapshot of data from your table with the desired fields and data
RsSql = "Select Messages, Minutes, Charges From 201205Summary"
'Open the recordset and test for EOF
Set Rs = CurrentDb.OpenRecordset(RsSql)
If Not Rs.EOF And Not Rs.BOF Then
Open strFile For Output As #fFile
Do Until Rs.EOF
'Loop across all fields in recordset delimiting them with a tab key
For i = 0 To Rs.Fields.Count - 1
strString = strString & Rs(i) & vbTab
Next
'Output the resulting string to the text file
Print #fFile, strString
'Reset the string to empty for the next record
strString = ""
'Move to the next record in the recordset
Rs.MoveNext
Loop
'Close the recordset and the text file
Rs.Close
Close #fFile
End If
'Destroy the instance of the recordset from memory
Set Rs = Nothing
End Function