Sorry, my typo. It's acExportDelim. (I told you you should look
TransferText up in the help file! <g>)
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Douglas
I pasted your text into the buttons on click event and changed the text
for my own query and location but when I click the button an error
message is displayed stating "Compile error: Variable not defined" I
click ok and it takes me back to the vb page with "asExportDelim"
highlighted
any idea what I'm doing wrong?
thanks
Steve
message Look up TransferText in the Help file.
The code in your button's Click event will be something like:
Private Sub MyButton_Click()
DoCmd.TransferText asExportDelim, , "NameOfQuery",
"C:\Folder\File.txt"
End Sub
If you want to prompt the user for the name of the file to use, see
http://www.mvps.org/access/api/api0001.htm at "The Access Web". (Yes,
I know that's overwhelming looking, but all you need to do is copy
everything between Code Start and Code End and paste it into a new
module. Once you've done that, put code like the sample at the top of
the page into your routine)
Private Sub MyButton_Click
Dim strFilter As String
Dim strSaveFileName As String
strFilter = ahtAddFilterItem(myStrFilter, "Text Files (*.txt)",
"*.txt")
strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
If Len(strSaveFileName) > 0 Then
DoCmd.TransferText asExportDelim, , "NameOfQuery",
"C:\Folder\File.txt"
End If
End Sub
Unfortunately, I don't believe you'll be able to get field names at
the top of the file.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Thanks Douglas
I created the query as you suggested and it worked perfectly.
How do I export the query using the TransferText method?
And would it be possible to link it to a command button on my form?
Regards
Steve
message You could create a query that has a single field:
SELECT [Id] & "~" & [Staff Number] & "~" & [First Name] & "~" &
[Surname]
FROM MyTable
ORDER BY [Id]
You could then export that query using the TransferText method.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
I have a query with the following fields
Id Staff Number First Name Surname
I need to save the query as a text file using the Tilde to separate
the fields, so it would look something like this.
1001~12345678~joe~smith
1002~87654321~fred~jones
etc
Using Access 97 & Windows XP
Any help would be appreciated
Steve