Concatenar campos en ACCESS
Tengo la siguiente función que concatena campos y los separa con ",". Quiero que cuando llegue al penúltimo campo le añada una "y" y cuando llegue al último no le añada nada.
Function resumenArticulosCliente(ByVal idCliente As Long) As String
Dim txt As String
Dim rs As Recordset
txt = "SELECT DISTINCT Articulos FROM Pedidos WHERE idCliente=" & idCliente & " ORDER BY Articulos"
Set rs = CurrentDb().OpenRecordset(txt)
If Not rs.EOF Then rs.MoveFirst
txt = ""
Do While Not rs.EOF
txt = txt & rs!Articulos & ", "
rs.MoveNext
Loop
rs.Close
resumenArticulosCliente = Trim$(txt)
End Function
Function resumenArticulosCliente(ByVal idCliente As Long) As String
Dim txt As String
Dim rs As Recordset
txt = "SELECT DISTINCT Articulos FROM Pedidos WHERE idCliente=" & idCliente & " ORDER BY Articulos"
Set rs = CurrentDb().OpenRecordset(txt)
If Not rs.EOF Then rs.MoveFirst
txt = ""
Do While Not rs.EOF
txt = txt & rs!Articulos & ", "
rs.MoveNext
Loop
rs.Close
resumenArticulosCliente = Trim$(txt)
End Function
Respuesta de Carlos soloffice
1