Access - JDMA

 
Vista:

JDMA

Publicado por Juan (5 intervenciones) el 20/11/2004 23:13:20
HOLA AMIGOS, COMO ESCRIBO EN PALABRAS UN TOTAL, SI TIENEN EL CODIGO ???? GRACIAS
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Cómo convertir un número a palabras

Publicado por Alejandro (4142 intervenciones) el 17/05/2023 23:26:38
Si deseas convertir un número en palabras en Access, puedes utilizar el siguiente código VBA como ejemplo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Function ConvertirEnPalabras(ByVal Numero As Double) As String
    Dim Unidades As Variant
    Dim Decenas As Variant
    Dim Centenas As Variant
    Dim StrNumero As String
    Dim i As Integer
 
    Unidades = Array("", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve")
    Decenas = Array("", "", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa")
    Centenas = Array("", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos")
 
    StrNumero = Format(Numero, "0.00")
    i = InStr(StrNumero, ".")
 
    If i > 0 Then
        ConvertirEnPalabras = ConvertirParteEntera(Mid(StrNumero, 1, i - 1)) & " pesos con " & ConvertirParteDecimal(Mid(StrNumero, i + 1))
    Else
        ConvertirEnPalabras = ConvertirParteEntera(StrNumero) & " pesos"
    End If
End Function
 
Function ConvertirParteEntera(ByVal ParteEntera As String) As String
    Dim Numero As Integer
    Dim StrNumero As String
 
    Numero = CInt(ParteEntera)
    StrNumero = ""
 
    If Numero < 20 Then
        StrNumero = Unidades(Numero)
    ElseIf Numero < 100 Then
        StrNumero = Decenas(Val(Left(ParteEntera, 1)))
        If Right(ParteEntera, 1) <> "0" Then
            StrNumero = StrNumero & " y " & Unidades(Val(Right(ParteEntera, 1)))
        End If
    Else
        StrNumero = Centenas(Val(Left(ParteEntera, 1)))
        If Val(Mid(ParteEntera, 2)) <> 0 Then
            StrNumero = StrNumero & " " & ConvertirParteEntera(Mid(ParteEntera, 2))
        End If
    End If
 
    ConvertirParteEntera = StrNumero
End Function
 
Function ConvertirParteDecimal(ByVal ParteDecimal As String) As String
    Dim Numero As Integer
    Dim StrNumero As String
 
    Numero = CInt(ParteDecimal)
    StrNumero = ""
 
    If Numero < 20 Then
        StrNumero = Unidades(Numero)
    ElseIf Numero < 100 Then
        StrNumero = Decenas(Val(Left(ParteDecimal, 1)))
        If Right(ParteDecimal, 1) <> "0" Then
            StrNumero = StrNumero & " y " & Unidades(Val(Right(ParteDecimal, 1)))
        End If
    End If
 
    ConvertirParteDecimal = StrNumero
End Function

Para utilizar este código, debes seguir estos pasos:

1. Abre tu base de datos en Access.
2. Crea un nuevo módulo en el menú "Insertar" -> "Módulo".
3. Copia y pega el código proporcionado en el nuevo módulo.
4. Guarda el módulo con un nombre descriptivo, como "ModuloConversion".
5. Cierra el editor de código.
6. En tu formulario o informe, crea un cuadro de texto donde deseas mostrar el total en palabras.
7. En la propiedad "Origen del control" del cuadro de texto, ingresa la siguiente expresión: `=ConvertirEnPalabras([Total])` (reemplaza `[Total]` con el nombre del campo que contiene el total que deseas convertir).
8. Guarda y abre el formulario o informe.

El cuadro de texto mostrará el total convertido en palabras.

Espero que esto te ayude a lograr lo que necesitas.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar