Ho anche provato anticipando le due stringhe sotto ai "set" in questo modo
codice:
Private Sub Comando20_Click()
Dim i As Integer
'Aggiungo il contatore - MODIFICA LIMITE A SECONDA DEI RECORD'
For i = 1 To 3 Dim myApp As Word.Application,
myDoc As Word.Document Set myApp = CreateObject("Word.Application")
Set myDoc = myApp.Documents.Add(Template:="scheda2.dot")
Dim myData As DAO.Database, myRec As DAO.Recordset
Set myData = CurrentDb
Dim cognome as long
Dim nome as long
Set cognome = myRec![cognome]
Set nome = myRec![nome]
'Compila il documento con i rispettivi campi'
Set myRec = myData.OpenRecordset("SELECT cognome, nome, cf, data FROM [esponenti] where ID like '" & i & "' ")
myDoc.FormFields("cognome").Result = myRec![cognome] myDoc.FormFields("nome").Result = myRec![nome] myDoc.FormFields("cf").Result = myRec![cf] myDoc.FormFields("data").Result = myRec![data]
ActiveDocument.SaveAs ("C:\Sound\" & cognome & " " & nome & ".doc")
myApp.Visible = True
Next 'myApp.Quit Set myApp = Nothing ' End Sub
ma restituisce l'errore run time 91 "variabile oggetto o variabile del blocco with non impostata"