Ciao Andrea,
prova in questo modo:
Sub mSalvaFiles()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim col As Collection
Dim vItem As Variant
Dim lFileNumber As Long
Dim strTesto As String
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT DISTINCT NomeFile From qrySalva", dbOpenSnapshot)
Set col = New Collection
With rst
Do While Not .EOF
col.Add Item:=CStr(!NomeFile)
.MoveNext
Loop
End With
For Each vItem In col
strTesto = vbNullString
Set rst = db.OpenRecordset("SELECT Dato1, Dato2 FROM qrySalva WHERE NomeFile = '" _
& vItem & "'", dbOpenSnapshot)
With rst
Do While Not .EOF
strTesto = strTesto & !Dato1 & vbTab & !Dato2 & vbCrLf
.MoveNext
Loop
End With
lFileNumber = FreeFile
Open CurrentProject.Path & "" & vItem For Output As #lFileNumber
Print #lFileNumber, strTesto
Close #lFileNumber
Next vItem
rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
End Sub
I nomi degli oggetti sono da adattare. Nel mio esempio la query di chiama qrySalva, il campo contenente il nome del file si chiama "NomeFile", il secondo e terzo campo li ho chiamati Dato1 e Dato2
David