Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

boton guardar

Estas en el tema de boton guardar en el foro de Visual Basic clásico en Foros del Web. hola a todos elabore un form y le agrege el botton guardar y lo programe de la siguiente manera: Código: Código: rivate Sub Command1_Click() codigo ...
  #1 (permalink)  
Antiguo 10/12/2009, 13:45
 
Fecha de Ingreso: abril-2007
Mensajes: 19
Antigüedad: 17 años
Puntos: 0
boton guardar

hola a todos elabore un form y le agrege el botton guardar y lo programe de la siguiente manera:
Código:
Código:
rivate Sub Command1_Click()

codigo = Val(Text3)
If codigo > 0 Then
    bandera = False
    With tabla
        If .BOF = False And .EOF = False Then .MoveFirst
       
        Do While Not .EOF
            If codigo = !ci Then bandera = True
            .MoveNext
        Loop

       If bandera = False Then
            .AddNew
            !nom = Text1
            !apell = Text2
            !ci = Text3
            !protecc = Text4
            !proyecn = Text5
            !taller = Text6
            !mate = Text7
            !leng = Text8
            !plan = Text9
            .Update
            MsgBox "Datos Almacenados", vbInformation, "AVISO"
            Limpiar
        Else
            MsgBox "Este Cedula ya existe", vbInformation, "AVISO"
            Limpiar
           
        End If
    End With
Else
    MsgBox "Debe agregar una Cedula para iniciar", vbCritical, "CUIDADO"
    Text1.SetFocus
End If

End Sub
trabaja bien sin error lo q quiero es como pero quiero saber como hago para q el boton se habilite cuando los campos esten llenos q si me falta un por llenar se mantenga desabilitado como cuando vamos a poner un key para un programa hasta q no llenas no se te habilita el boton siguiente
  #2 (permalink)  
Antiguo 10/12/2009, 17:49
 
Fecha de Ingreso: abril-2005
Ubicación: Piura - Perú
Mensajes: 189
Antigüedad: 19 años
Puntos: 0
Respuesta: boton guardar

Una solución es asignarles banderas a cada text, y un comprobador de el resto de banderas para el resto de text, algo asi:

Código:
Private Sub Text1_Change()
 
  If Not (text1.text="") then 
    bandera1=true
    If (bandera1=true) and (bandera2=true) and (bandera3=true) then
       Command1.enabled = true
    end if
  Else
    bandera1=False
    Command1.enabled = False
  End if
 
End Sub 
 
Private Sub Text2_Change()
 
  If Not (text2.text="") then 
    bandera2=true
    If (bandera1=true) and (bandera2=true) and (bandera3=true) then
       Command1.enabled = true
    end if
  Else
    bandera2=False
    Command1.enable = False
  End If
 
End Sub
 
Private Sub Text3_Change()
 
  If Not (text3.text="") then 
    bandera3=true
    If (bandera1=true) and (bandera2=true) and (bandera3=true) then
       Command1.enabled = true
    end if
  Else
    bandera3=False
    Command1.enabled = False
  End If
 
End Sub
El ejemplo es aplicado para 3 text, tendrias que agregar el resto para con las demàs cajas de texto

Última edición por KenMasters; 10/12/2009 a las 17:57
  #3 (permalink)  
Antiguo 10/12/2009, 17:57
 
Fecha de Ingreso: abril-2005
Ubicación: Piura - Perú
Mensajes: 189
Antigüedad: 19 años
Puntos: 0
Respuesta: boton guardar

Aunque tienes tambièn para realizar de la siguiente manera

En cada caja de text colocas
Código:
Private Sub Text1_Change()
If Not (text1.text="") And (text2.text="") And (text3.text="") then
  Command1.enabled = true
else
  Command1.enabled = false
end if
End sub
  #4 (permalink)  
Antiguo 11/12/2009, 09:34
 
Fecha de Ingreso: noviembre-2006
Mensajes: 227
Antigüedad: 17 años, 6 meses
Puntos: 6
Respuesta: boton guardar

Otra forma muy sencilla es utilizando un Timer mas o menos asi:

Código:
'dentro de la propiedades del Timer donde dice Interval le colocas 1
'y usas este codigo
Private Sub Timer1_Timer()

    If Trim(Text1.Text) = "" Or Trim(Text2.Text) = "" Then
        TuCommandButton.Enable = False
        Else
        TuCommandButton.Enable = True
    End If

End Sub
Agregas tantos TextBox como tu deseas y si ha uno le falta un campo seguira inabilitado tu command si no te lo habilita

Espero te sirva y nos vemos
  #5 (permalink)  
Antiguo 11/12/2009, 11:19
Avatar de pkj
pkj
 
Fecha de Ingreso: julio-2006
Ubicación: Órbita sincrónica
Mensajes: 899
Antigüedad: 17 años, 9 meses
Puntos: 29
Respuesta: boton guardar

Siguiendo el ejemplo anterior, también puedes automatizar más así:

Código vb:
Ver original
  1. Private Sub Timer1_Timer()
  2.   Dim Cn As Control
  3.   For Each Cn In Me.Controls
  4.     If Left$(Cn.Name, 4) = "Text" Then
  5.       If Trim(Cn.Text) = "" Then
  6.         Command1.Enabled = False
  7.         Exit Sub
  8.       End If
  9.     End If
  10.   Next Cn
  11.   Command1.Enabled = True
  12. End Sub

Por otro lado un Interval de 100 en el timer es más que suficiente.

Saludos
__________________
No hay preguntas tontas, solo gente estup..., ¡No!, ¿como era? No hay gente que pregunte a tontos... ¡Nooo!... ¡Vaya cabeza!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:04.