[Tex/LaTex] Datatool error: undefined control sequence \begin

datatoolerrors

I'm using datatool to make a mail merge.

I have my .csv file.
I've defined my \DTLloaddb{indirizzi}{/home/kde/Dropbox/edile_150/consulenti_arezzo.csv}
and if I use \DTLdisplaydb{indirizzi}
I have my table printed on the doc.

But if I try to make that:

\begin{document}

\DTLforeach*{indirizzi}{%
\nome=nome, \cognome=cognome,%
\num=num, \via=VIA, \civico=civico, \localita=localita \cap=cap,%
\provincia=provincia, \tel=tel
}
\begin{letter}

%\DTLdisplaydb{indirizzi}

{\nome\ \cognome\\
\via, \civico\ \num\\
\via \civico \localita \\
\cap \provincia \tel}

when I make a PDF, I receive this error:

undefined control sequence \begin

The line number is the same of \begin{letter}
and then other errors

(Missing control sequence \begin)

I can't understand why I receive this error.

Best Answer

There are some errors in your input.

\begin{document}

\DTLforeach*{indirizzi}{%
\nome=nome, \cognome=cognome,%
\num=num, \via=VIA, \civico=civico, \localita=localita, \cap=cap,%
\provincia=provincia, \tel=tel}
{\begin{letter}
  {\nome\ \cognome\\
  \via, \civico\ \num\\
  \via \civico \localita \\
  \cap \provincia \tel}}

A comma was missing after localita; more important, \DTLforeach* requires three arguments: the symbolic name of the database, the assignments and the text that must be acted on. With braces around \begin{letter}{...} the document should be processed correctly.