In addition to what June7 said, I saw a couple of other problems. It looks like you want the name of the text file to be the style. Try the following:
Code:
Option Compare Database
Option Explicit
Sub mySub()
Dim rstStyle As DAO.Recordset
Dim sSQL As String
Set rstStyle = CurrentDb.OpenRecordset("SELECT DISTINCT [style] FROM test")
If Not (rstStyle.BOF And rstStyle.EOF) Then
rstStyle.MoveFirst
'Process until end of file
Do While Not rstStyle.EOF
sSQL = "SELECT test.*"
sSQL = sSQL & " INTO [text;DATABASE=C:\sample\]." & rstStyle!Style & ".txt"
sSQL = sSQL & " FROM test where test.style = '" & rstStyle!Style & "'"
'uncomment the following line and set a breakpoint to see the SQL
' Debug.Print sSQL
CurrentDb.Execute sSQL, dbFailOnError
rstStyle.MoveNext
Loop
End If
rstStyle.Close
Set rstStyle = Nothing
End Sub