
Public Function Generar_Id_Llamada() As String
On Error GoTo MiError
LLamadaDAO
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = cn
.Source = "SELECT TOP 1 Id_Llamada FROM LLamada ORDER BY Id_Llamada Desc"
.CursorLocation = adUseClient
.Open
End With
If TypeName(rs) = "Recordset" And Not rs.EOF Then
ultimo = rs(0)
Else
ultimo = 0
End If
If ultimo = 0 Then
Generar_Id_Llamada = "T0000"
Else
num = CInt(Right(Trim(ultimo), 3)) + 1
If Len(CStr(num)) = 1 Then
numcad = "000" + CStr(num)
ElseIf Len(CStr(num)) = 2 Then
numcad = "00" + CStr(num)
ElseIf Len(CStr(num)) = 3 Then
numcad = CStr(num)
End If
Generar_Id_Llamada = Left(Trim(ultimo), 3) + CStr(numcad)
End If
Set rs = Nothing
Exit Function
MiError:
MsgBox Err.Description, vbCritical, "Error"
End Function
Pero algo esta funcionando mal porque lo que obtengo como IDs son los siguientes: T0000, T000001, T000002 ..... T000009 .... T000021, T000022 .... T000099, T00100, T00101, T00102... T00560 ... T00840 .. etc
como ven se empieza a acortar


Espero puedan darme una ayuda para poder corregir este codigo!!
Gracias!!!
