Sustituir un imputbox por textbox

Tengo un formulario que me recoge información de in imputbox y desearía sustituirlo por un texbox

Adjunto parte de el código.

Private Sub CommandButton1_Click()
'Registrar producto y capturar cantidad
'Declaramos variables
Dim strDescripcion As String
Dim intCantidad As Long 
Dim doublePUnitario As Long
Dim intTotal As Double

'
'En caso de error
On Error GoTo ErrorHandler
'
With Application.WorksheetFunction
'
'Usamos BUSCARV para encontrar el detalle del producto
'
strDescripcion = .VLookup(CDbl(Me.TextBox1.Value), PRODUCTOS.Range("C:E"), 2, 0)
'
'
<'intCantidad = InputBox(strDescripcion & vbNewLine & vbNewLine & "Ingresa la cantidad.", "Cantidad", 1)> Este es código que deseo sustituir por el valor que me ingrese desde el textbox...
FrmCantidad.Show
intCantidad = FrmCantidad.TxtCant
'
If intCantidad = 0 Then GoTo ErrorHandler
'
'Llenamos el ListBox
'... Código
Me.ListBox1.AddItem Me.TextBox1.Value
'
'... DESCRIPCIÓN
ListBox1.List(ListBox1.ListCount - 1, 1) = strDescripcion
'
'... CANTIDAD
ListBox1.List(ListBox1.ListCount - 1, 2) = Format(intCantidad, "General Number")
'
'... P.unitario
doublePUnitario = .VLookup(CDbl(Me.TextBox1.Value), PRODUCTOS.Range("C:E"), 3, 0)
ListBox1.List(ListBox1.ListCount - 1, 3) = Format(doublePUnitario, "Currency")
'
'... TOTAL
intTotal = doublePUnitario * intCantidad
ListBox1.List(ListBox1.ListCount - 1, 4) = Format(intTotal, "Currency")
'
'...ETIQUETAS
Me.lblProductos = Format(CLng(Me.lblProductos) + intCantidad, "General Number")
Me.lblTotal = Format(CDbl(Me.lblTotal) + CDbl(intTotal), "Currency")
Me.lblCambio = Format(CDbl(Me.lblCancela) - CDbl(Me.lblTotal), "Currency")
'
Me.TextBox1.Value = ""
Me.TextBox1.SetFocus
'
End With
'
Exit Sub
'
ErrorHandler:
'
MsgBox "Revisar Codigo de Producto: " & Err.Description, vbExclamation, "EXCELeINFO"
'
Me.TextBox1.Value = ""
Me.TextBox1.SetFocus
'
End Sub

1 respuesta

Respuesta
2

Y si simplemente agregas el textbox txtCantidad en el formulario, sería más práctico que abrir otro userform


Otro detalle, si declaras la variable intCantidad como long, pero luego le pasas un texto, te va a enviar el error: "No coinciden los tipos"

Para ello debes convertir el texto a valor numérico.


Pero si lo quieres en otro formulario, entonces realiza lo siguiente:

En el primer UserForm, en la primer línea de todo el código, es decir, en las "Declaraciones General", pon la siguiente declaración:

Public intCantidad As Long

En el userform FrmCantidad, en un botón pon lo siguiente:

Private Sub CommandButton1_Click()
'Salir de FrmCantidad
    If TxtCant.Value = "" Or Not IsNumeric(TxtCant.Value) Then
    Else
        UserForm1.intCantidad = CDbl(TxtCant.Value)
    End If
    Unload Me
End Sub

Significa que le va a enviar al formulario1 en la variable pública intCantidad el contenido que tiene en el TxtCant

Cambia UserForm1 por el nombre de tu primer userform


Después en tu primer userform, solamente tienes que usar la variable, por ejemplo:

 '... TOTAL
    intTotal = doublePUnitario * intCantidad

Avísame cualquier duda.


Añade tu respuesta

Haz clic para o

Más respuestas relacionadas