Error con la función "Enletra" al crear y enlazar una base de datos con el programa Access 2000

Hola. Tengo un "problemilla" desde hace bastante tiempo que no consigo solucionar. Tengo 2 campos uno tipo moneda CAMPO1 y el otro texto CAMPO 2. Quiero que al introducir una cifra en el campo 1 me ponga automaticamente el esa cifra en letra en el campo 2. Lei que era con la funcion ENLETRA, pero me da error #Nombre?. Lo mismo me ocurre con la funcion TEXTO. Como puedo conseguir hacerlo. Gracias por tu ayuda. Ah trabajo con Access 2000

1 respuesta

Respuesta
1
Te envio una funcion que desarrolle para eso...
Private Sub Form_Current()
'If Me!PLATOT < 100000000000 Then
Me!LETRAS = num_to_letras(Me!PLATOT * 100)
'Else
'MsgBox ("Numero muy grande...digite uno menor o igual a 9,999,999,999,999,99")
'End If
End Sub
Ojala te sirva....saludos
'/*-----------------------------------------------------------------------**/
'/* | B | | | | , | | | | M | | | | , | | | | . |*/
'/* | I | | | | , | | | | I | | | | , | | | | . |*/
'/* | L | | | | , | | | | L | | | | , | | | | . |*/
'/* | L | | | | , | | | | L | | | | , | | | | . |*/
'/* | O | | | | , | | | | O | | | | , | | | | . |*/
'/* | N | | | | , | | | | N | | | | , | | | | . |*/
'/*---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|*/
'/* 1 | | 2 | 3 | 4 | | 5 | 6 | 7 | | 8 | 9 | 0 | |11 |12 |13 | |*/
'/*---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|*/
'/*C07|C08|C09|C10|C11|C12|C13|C14|C15|C16|C17|C18|C19|C20|C21|C22|C23|C24|*/
'/*-----------------------------------------------------------------------**/
Dim aux1, aux2, aux3 As Double
Dim lnum, xlet As String
Dim c07, c08, c09, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c25, c26, c27 As String
Dim t1, t2, t3, t4, t5 As String
c07 = ""
c08 = ""
c09 = ""
c10 = ""
c11 = ""
c12 = ""
c13 = ""
c14 = ""
c15 = ""
c16 = ""
c17 = ""
c18 = ""
c19 = ""
c20 = ""
c21 = ""
c22 = ""
c23 = ""
c25 = " "
c26 = ""
c27 = ""
xlet = Space$(198)
lnum = Space$(15)
c27 = "/100 DOLARES AMERICANOS"
'/* -------------------- */
'/* TABLAS DE CONSTANTES */
'/* -------------------- */
t1 = "UN DOS TRES CUATRO CINCO SEIS SIETE OCHO NUEVE "
t2 = "ONCE DOCE TRECE CATORCE QUINCE "
T3 = "diez veinte treinta cuarenta cincuenta sesenta setenta ochenta noventa "
t4 = "DIECI VEINTI TREINTAI CUARENTAI CINCUENTAISESENTAI SETENTAI OCHENTAI NOVENTAI "
T5 = "ciento doscientos trescientos cuatrocientos quinientos seiscientos setecientos ochocientos novecientos "
' /* ---------------------------- */
' /* ARMANDO LAS CONSTANTES */
' /* ---------------------------- */
lnum = Space(15 - Len(Trim(Str(NUM)))) + Trim(Str(NUM))
If NUM > 99999999999999# Then
c08 = " BILLON"
End If
If NUM > 199999999999999# Then
c08 = " BILLONES "
End If
' /* C12 */
aux3 = Val(Mid$(lnum, 2, 3))
If aux3 > 0 Then
c12 = " MIL "
End If
' /* C16 */
If NUM > 99999999 Then
c16 = " MILLON "
End If
If NUM > 199999999 Then
c16 = " MILLONES "
End If
If Mid$(lnum, 2, 6) = "000000" Then
c16 = " "
End If
' /* C20 */
aux3 = Val(Mid$(lnum, 8, 3))
If aux3 > 0 Then
c20 = " MIL "
End If
' /* C23 */
If Mid$(lnum, 1, 15) = "000000000000000" Then
c23 = "CERO "
End If
' /* ---------------------------- */
' /* C07 (BILLONES DE N.SOL) */
' /* ---------------------------- */
aux1 = Val(Mid$(lnum, 1, 1))
If aux1 > 0 Then
aux2 = aux1 * 7 - 6
c07 = Trim(Mid$(t1, aux2, 7)) + " "
End If
' /* ---------------- */
' /* CENTENAS */
' /* ---------------- */
' /**** PARA C09 ******/
aux1 = Val(Mid$(lnum, 2, 1))
If aux1 > 0 Then
aux2 = aux1 * 14 - 13
c09 = Trim(Mid$(t5, aux2, 14)) + " "
End If
If aux1 = 1 And Mid$(lnum, 3, 2) = "00" Then
c09 = " CIEN "
End If
' /**** PARA C13 ******/
aux1 = Val(Mid$(lnum, 5, 1))
If aux1 > 0 Then
aux2 = aux1 * 14 - 13
c13 = Trim(Mid$(t5, aux2, 14)) + " "
End If
If aux1 = 1 And Mid$(lnum, 6, 2) = "00" Then
c13 = " CIEN "
End If
' /**** PARA C17 ******/
aux1 = Val(Mid$(lnum, 8, 1))
If aux1 > 0 Then
aux2 = aux1 * 14 - 13
c17 = Trim(Mid$(t5, aux2, 14)) + " "
End If
If aux1 = 1 And Mid$(lnum, 9, 2) = "00" Then
c17 = " CIEN "
End If
' /**** PARA C21 ******/
aux1 = Val(Mid$(lnum, 11, 1))
If aux1 > 0 Then
aux2 = aux1 * 14 - 13
c21 = Trim(Mid$(t5, aux2, 14)) + " "
End If
If aux1 = 1 And Mid$(lnum, 12, 2) = "00" Then
c21 = " CIEN "
End If
' /* ---------------- */
' /* DECENAS */
' /* ---------------- */
' /**** PARA C10 ******/
aux1 = Val(Mid$(lnum, 3, 1))
If aux1 > 0 And Mid$(lnum, 4, 1) = "0" Then
aux2 = aux1 * 10 - 9
c10 = Trim(Mid$(t3, aux2, 10)) + " "
Else
aux2 = Val(Mid$(lnum, 3, 2))
If aux2 > 15 Then
aux2 = aux1 * 10 - 9
c10 = Trim(Mid$(t4, aux2, 10))
End If
aux2 = Val(Mid$(lnum, 3, 2))
If aux2 > 10 And aux2 < 16 Then
aux1 = Val(Mid$(lnum, 4, 1))
aux2 = aux1 * 11 - 10
c10 = Trim(Mid$(t2, aux2, 11)) + " "
End If
End If
' /**** PARA C14 ******/
aux1 = Val(Mid$(lnum, 6, 1))
If aux1 > 0 And Mid$(lnum, 7, 1) = "0" Then
aux2 = aux1 * 10 - 9
c14 = Trim(Mid$(t3, aux2, 10)) + " "
Else
aux2 = Val(Mid$(lnum, 6, 2))
If aux2 > 15 Then
aux2 = aux1 * 10 - 9
c14 = Trim(Mid$(t4, aux2, 10))
End If
aux2 = Val(Mid$(lnum, 6, 2))
If aux2 > 10 And aux2 < 16 Then
aux1 = Val(Mid$(lnum, 7, 1))
aux2 = aux1 * 11 - 10
c14 = Trim(Mid$(t2, aux2, 11)) + " "
End If
End If
' /**** PARA C18 ******/
aux1 = Val(Mid$(lnum, 9, 1))
If aux1 > 0 And Mid$(lnum, 10, 1) = "0" Then
aux2 = aux1 * 10 - 9
c18 = Trim(Mid$(t3, aux2, 10)) + " "
Else
aux2 = Val(Mid$(lnum, 9, 2))
If aux2 > 15 Then
aux2 = aux1 * 10 - 9
c18 = Trim(Mid$(t4, aux2, 10))
End If
aux2 = Val(Mid$(lnum, 9, 2))
If aux2 > 10 And aux2 < 16 Then
aux1 = Mid$(lnum, 10, 1)
aux2 = aux1 * 11 - 10
c18 = Trim(Mid$(t2, aux2, 11)) + " "
End If
End If
' /**** PARA C22 ******/
aux1 = Val(Mid$(lnum, 12, 1))
If aux1 > 0 And Mid$(lnum, 13, 1) = "0" Then
aux2 = aux1 * 10 - 9
c22 = Trim(Mid$(t3, aux2, 10)) + " "
Else
aux2 = Val(Mid$(lnum, 12, 2))
If aux2 > 15 Then
aux2 = aux1 * 10 - 9
c22 = Trim(Mid$(t4, aux2, 10))
End If
aux2 = Val(Mid$(lnum, 12, 2))
If aux2 > 10 And aux2 < 16 Then
aux1 = Mid$(lnum, 13, 1)
aux2 = aux1 * 11 - 10
c22 = Trim(Mid$(t2, aux2, 11)) + " "
End If
End If
' /* ---------------- */
' /* UNIDADES */
' /* ---------------- */
' /**** PARA C11 ******/
aux1 = Val(Mid$(lnum, 4, 1))
aux2 = Val(Mid$(lnum, 3, 2))
If aux1 > 0 And aux2 < 10 Then
aux2 = aux1 * 7 - 6
c11 = Trim(Mid$(t1, aux2, 7)) + " "
End If
aux2 = Val(Mid$(lnum, 3, 2))
If aux1 > 0 And aux2 > 15 Then
aux2 = aux1 * 7 - 6
c11 = Trim(Mid$(t1, aux2, 7)) + " "
End If
' /**** PARA C15 ******/
aux1 = Val(Mid$(lnum, 7, 1))
aux2 = Val(Mid$(lnum, 6, 2))
If aux1 > 0 And aux2 < 10 Then
aux2 = aux1 * 7 - 6
c15 = Trim(Mid$(t1, aux2, 7)) + " "
End If
aux2 = Val(Mid$(lnum, 6, 2))
If aux1 > 0 And aux2 > 15 Then
aux2 = aux1 * 7 - 6
c15 = Trim(Mid$(t1, aux2, 7)) + " "
End If
' /**** PARA C19 ******/
aux1 = Val(Mid$(lnum, 10, 1))
aux2 = Val(Mid$(lnum, 9, 2))
If aux1 > 0 And aux2 < 10 Then
aux2 = aux1 * 7 - 6
c19 = Trim(Mid$(t1, aux2, 7)) + " "
End If
aux2 = Val(Mid$(lnum, 9, 2))
If aux1 > 0 And aux2 > 15 Then
aux2 = aux1 * 7 - 6
c19 = Trim(Mid$(t1, aux2, 7)) + " "
End If
' /**** PARA C23 ******/
aux1 = Val(Mid$(lnum, 13, 1))
aux2 = Val(Mid$(lnum, 12, 2))
If aux1 > 0 And aux2 < 10 Then
aux2 = aux1 * 7 - 6
c23 = Trim(Mid$(t1, aux2, 7)) + " "
End If
aux2 = Val(Mid$(lnum, 12, 2))
If aux1 > 0 And aux2 > 15 Then
aux2 = aux1 * 7 - 6
c23 = Trim(Mid$(t1, aux2, 7)) + " "
End If
' /* ---------------- */
'/* DECIMALES */
'/* ---------------- */
'/**** PARA C26 ******/
c26 = Mid$(lnum, 14, 2)
'/* ---------------------------- */
'/* ARMANDO IMPORTE EN LETRAS */
'/* ---------------------------- */
xlet = "***" + c07 + c08 + c09 + c10 + c11 + c12 + c13 + c14 + c15 + c16 + c17 + c18 + c19 + c20 + c21 + c22 + c23 + c25 + c26 + c27
If NUM > 0 Then
num_to_letras = xlet
Else
num_to_letras = ""
End If
End Function
Public Function mes_actual()
Dim mes As Integer
Dim Nombre As String
mes = Month(Date)
Select Case mes
Case 1
Nombre = "Enero"
Case 2
Nombre = "Febrero"
Case 3
Nombre = "MARZO"
Case 4
Nombre = "ABRIL"
Case 5
Nombre = "MAYO"
Case 6
Nombre = "JUNIO"
Case 7
Nombre = "JULIO"
Case 8
Nombre = "AGOSTO"
Case 9
Nombre = "SEPTIEMBRE"
Case 10
Nombre = "OCTUBRE"
Case 11
Nombre = "NOVIEMBRE"
Case 12
Nombre = "DICIEMBRE"
End Select
mes_actual = Nombre
End Function
Muchas gracias por tu respuesta tan rapida, pero creo que no lo estoy haciendo bien. Esto de trabajar con modulos y demás nunca lo he echo.
He creado un modulo con la funcion que me diste, tal cual. y en el formulario importe en letra y en origen de control le he puesto el modulo creado, que me pone mes_actual, y cuando lo pongo en vista formulario me indica el mes en el que estamos... No sé como hacerlo para que me coja la cifra del campo BASE y lo ponga en letra en el campo IMPORTE EN LETRA. Muchas gracias por tu ayuda...
En la primera linea del modulo tienes que poner
Public Function num_to_letras(NUM As Double)
Y ahi seguro te funcionara...
Hola otra vez shark, muchas gracias por todo, pero creo que sigo haciendo algo mal. He puesto la primera linea que me dijiste y en origen de control =num_to_letras([base]).
base por que es el campo de donde quiero que "recoja" la cifra para cambiarla a texto. Y me da error#. ¿Que hago mal? Muchas gracias otra vez...
Se supone que tienes un formulario, y ahi una variable que es el monto numerico ( base )
Entonces asociale a esta variable el evento after update... entonce quedaria asi
Private Sub base_AfterUpdate()
letras=NUM_TO_LETRAS(base)
End Sub
Y letras es la variable donde pondra el valor del numero en letras

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas