PDA

View Full Version : Texbox null



jpl
04-20-2006, 04:58 AM
Hello I am doing a userform that has various textbox and a command boton and need controlling if the contents of the texbox is null, when does click in the comand boton

Thank you

lucas
04-20-2006, 05:54 AM
Hi jpl,
I think this will work.....

Dim ctrl As Control
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "TextBox" Then
ctrl.Text = ""
End If
Next ctrl

use it in the code for your command button.

jpl
04-21-2006, 02:11 AM
Thank you by your interest
what want to do is that in <userform> that has textbox, these textbox are variables of a document and therefore can not be null, because for the program, the code that have been the following and functions to me to half.

Option Explicit

Private Sub cmdcancel_Click()
Unload Me
'Opcion por si quiero cerra el documento sin guardar:
'ActiveDocument.Close SaveChanges:=False
End Sub
Private Sub cmdLimpia_Click()
txtNombreCliente.Value = "-"
TxtNombreAnteproyecto.Value = "-"
TxtNumeroAnteproyecto.Value = "-"
TxtRevision.Value = "-"
TxtFechaRevision.Value = "-"
TxtClienteFinal.Value = "-"
TxtAutor1.Value = "-"
TxtAutor2.Value = "-"
CboComentarioRevision.Value = "-"
txtNombreCliente.SetFocus

End Sub
Private Sub cmdOK_Click()
Application.ScreenUpdating = False
'***** Controla cajas de texto vac?as *****
'Cliente
If Len(Trim(txtNombreCliente)) = 0 Then
MsgBox ("Datos de cliente")
Beep
txtNombreCliente.SetFocus
Else
'Proyecto
If Len(Trim(TxtNombreAnteproyecto)) = 0 Then
MsgBox ("Datos de Proyecto")
Beep
TxtNombreAnteproyecto.SetFocus
Else
'Cliente final
If Len(Trim(TxtClienteFinal)) = 0 Then
MsgBox ("Datos de cliente final")
Beep
TxtClienteFinal.SetFocus
Else
'Numero anteproyecto
If Len(Trim(TxtNumeroAnteproyecto)) = 0 Then
MsgBox ("N?mero anteproyecto")
Beep
TxtNumeroAnteproyecto.SetFocus
Else
'Revision
If Len(Trim(TxtRevision)) = 0 Then
MsgBox ("Revision")
Beep
TxtRevision.SetFocus
Else
'Fecha de revisi?n
If Len(Trim(TxtFechaRevision)) = 0 Then
MsgBox ("Fecha de revision")
Beep
TxtFechaRevision.SetFocus
Else
'Autor1
If Len(Trim(TxtAutor1)) = 0 Then
MsgBox ("Proyecto mec?nico")
Beep
TxtAutor1.SetFocus
Else
'Autor2
If Len(Trim(TxtAutor2)) = 0 Then
MsgBox ("Proyecto el?ctrico")
Beep
TxtAutor2.SetFocus
Else
End If
End If
End If
End If
End If
End If
End If
End If
'******************************************************
Dim Cadena1 As String
Dim Cadena2 As String
Dim Cadena3 As String
ActiveDocument.Variables("NombreCliente").Value = (txtNombreCliente.Value)
ActiveDocument.Variables("NombreAnteproyecto").Value = TxtNombreAnteproyecto.Value
ActiveDocument.Variables("NumeroAnteproyecto").Value = TxtNumeroAnteproyecto.Value
ActiveDocument.Variables("Revision").Value = TxtRevision.Value
ActiveDocument.Variables("FechaRevision").Value = TxtFechaRevision.Value
ActiveDocument.Variables("ComentarioRevision").Value = CboComentarioRevision.Value
ActiveDocument.Variables("ClienteFinal").Value = TxtClienteFinal.Value
ActiveDocument.Variables("Autor1").Value = TxtAutor1.Value
ActiveDocument.Variables("Autor2").Value = TxtAutor2.Value

Cadena1 = ActiveDocument.Variables("ClienteFinal").Value
Cadena2 = ActiveDocument.Variables("NumeroAnteProyecto").Value
Cadena3 = ActiveDocument.Variables("Revision").Value
ActiveDocument.Variables("Nombrefile").Value = Cadena1 & "-" & Cadena2 & "-" & Cadena3

Application.ScreenUpdating = True
ActiveDocument.Fields.Update
Unload Me
End Sub
Private Sub CmdTomaDatos_Click()
'CAMPOS DE DATOS DE PROYECTO
txtNombreCliente.Value = ActiveDocument.Variables("NombreCliente").Value
TxtNombreAnteproyecto.Value = ActiveDocument.Variables("NombreAnteproyecto").Value
TxtNumeroAnteproyecto.Value = ActiveDocument.Variables("NumeroAnteproyecto").Value
TxtRevision.Value = ActiveDocument.Variables("Revision").Value
TxtFechaRevision.Value = ActiveDocument.Variables("FechaRevision").Value
CboComentarioRevision.Value = ActiveDocument.Variables("ComentarioRevision").Value
TxtClienteFinal.Value = ActiveDocument.Variables("ClienteFinal").Value
TxtAutor1.Value = ActiveDocument.Variables("Autor1").Value
TxtAutor1.Value = ActiveDocument.Variables("Autor2").Value

End Sub
Private Sub UserForm_Initialize()
ActiveDocument.Subdocuments.Expanded = True
CboComentarioRevision.AddItem "New"
CboComentarioRevision.AddItem "Revision"
txtNombreCliente.Value = ActiveDocument.Variables("NombreCliente").Value
TxtNombreAnteproyecto.Value = ActiveDocument.Variables("NombreAnteproyecto").Value
TxtNumeroAnteproyecto.Value = ActiveDocument.Variables("NumeroAnteproyecto").Value
TxtRevision.Value = ActiveDocument.Variables("Revision").Value
TxtFechaRevision.Value = ActiveDocument.Variables("FechaRevision").Value
CboComentarioRevision.Value = ActiveDocument.Variables("ComentarioRevision").Value
TxtClienteFinal.Value = ActiveDocument.Variables("ClienteFinal").Value
TxtAutor1.Value = ActiveDocument.Variables("Autor1").Value
TxtAutor2.Value = ActiveDocument.Variables("Autor2").Value
txtNombreCliente.SetFocus

End Sub

TonyJollans
04-23-2006, 04:50 AM
Hi jpl,

Welcome to VBAX!

I (think I) can see what you want to do but what, exactly, is the problem? Does your code not work?

jpl
04-24-2006, 01:51 AM
The code works by halves, basically what I want to do is that texbox which are viculados to variables of documents, by means of a form to update them all, the problem is that when one of these texbox is empty the variables ?st? in target and the program funciona.No I do not know where to put the control of the text empty Thanks

TonyJollans
04-24-2006, 02:27 AM
I'm not sure if I'm understanding correctly but I think I see a problem.

In the CmdOK_Click procedure you check all the textboxes for text and if you find an empty one you set the focus to it, but ... your code keeps on running.

After your big set of nested Ifs, if you have found an empty textbox you will have moved the focus, so you could check that to see whether to continue ...

:
:
End If

If Me.ActiveControl.Name <> "CmdOK" Then Exit Sub

Dim Cadena1 As String
:
:

jpl
04-27-2006, 11:03 PM
I leave the code of since I have solved it


Option Explicit

Private Sub cmbAcerca_Click()
FrmAbout.Show
End Sub

Private Sub cmdcancel_Click()
Unload Me
'Opcion por si quiero cerra el documento sin guardar:
'ActiveDocument.Close SaveChanges:=False
End Sub
Public Function fCheckBlankFields()
Dim formulariocargado As Boolean
Dim formu As UserForm
Set formu = FrmDatos
Dim ctl As Control
Dim ctlName As String
Dim Aviso As String
Dim PrimerBlanco As String
PrimerBlanco = ""
Dim Camposenblanco As String
Camposenblanco = ""
'Recorremos los textboxes
For Each ctl In formu.Controls
If TypeOf ctl Is TextBox Then
ctlName = ctl.Name
If Len(ctl.Value) = 0 Or ctl.Text = "-" Then
If Len(Camposenblanco) = 0 Then
PrimerBlanco = ctl.Name
Camposenblanco = ctlName & vbCrLf
Else
Camposenblanco = Camposenblanco & ctlName & vbCrLf
End If
End If
End If
Next ctl
'Ahora, avisamos sobre los campos que hemos encontrado en blanco
If Len(Camposenblanco) > 0 Then
Aviso = "Los siguientes campos est&#225;n vacios: " & vbCrLf & Camposenblanco & _
" No puedes continuar sin rellenarlos " & vbCrLf & _
"&#191;Deseas completarlos? Si no los rellenas y pulsas en cancelar sales del formulario """
If MsgBox(Aviso, vbYesNo) = vbYes Then
' CmdTomaDatos.Enabled = False
FrmDatos.Controls(PrimerBlanco).SetFocus
Else
Unload Me
End If
Else
CmdTomaDatos.Enabled = True
End If
End Function
Private Sub cmdLimpia_Click()
txtNombreCliente.Value = "-"
TxtNombreAnteproyecto.Value = "-"
TxtNumeroAnteproyecto.Value = "-"
TxtRevision.Value = "-"
TxtFechaRevision.Value = "-"
TxtClienteFinal.Value = "-"
TxtAutor1.Value = "-"
TxtAutor2.Value = "-"
CboComentarioRevision.Value = "-"
txtNombreCliente.SetFocus

End Sub
Private Sub cmdOK_Click()
'Propuesta por Marta MVP de las new de microsot
fCheckBlankFields
Dim formulariocargado As Boolean
Application.ScreenUpdating = False
Dim Cadena1 As String
Dim Cadena2 As String
Dim Cadena3 As String
ActiveDocument.Variables("NombreCliente").Value = txtNombreCliente.Value
ActiveDocument.Variables("NombreAnteproyecto").Value = TxtNombreAnteproyecto.Value
ActiveDocument.Variables("NumeroAnteproyecto").Value = TxtNumeroAnteproyecto.Value
ActiveDocument.Variables("Revision").Value = TxtRevision.Value
ActiveDocument.Variables("FechaRevision").Value = TxtFechaRevision.Value
ActiveDocument.Variables("ComentarioRevision").Value = CboComentarioRevision.Value
ActiveDocument.Variables("ClienteFinal").Value = TxtClienteFinal.Value
ActiveDocument.Variables("Autor1").Value = TxtAutor1.Value
ActiveDocument.Variables("Autor2").Value = TxtAutor2.Value
Application.ScreenUpdating = True
ActiveDocument.Fields.Update
formulariocargado = True
End Sub

Private Sub CmdTomaDatos_Click()
'CAMPOS DE DATOS DE PROYECTO
txtNombreCliente.Value = ActiveDocument.Variables("NombreCliente").Value
TxtNombreAnteproyecto.Value = ActiveDocument.Variables("NombreAnteproyecto").Value
TxtNumeroAnteproyecto.Value = ActiveDocument.Variables("NumeroAnteproyecto").Value
TxtRevision.Value = ActiveDocument.Variables("Revision").Value
TxtFechaRevision.Value = ActiveDocument.Variables("FechaRevision").Value
CboComentarioRevision.Value = ActiveDocument.Variables("ComentarioRevision").Value
TxtClienteFinal.Value = ActiveDocument.Variables("ClienteFinal").Value
TxtAutor1.Value = ActiveDocument.Variables("Autor1").Value
TxtAutor1.Value = ActiveDocument.Variables("Autor2").Value
End Sub

Private Sub UserForm_Initialize()
'Propuesta por Marta MVP
Dim formulariocargado As Boolean
If formulariocargado = False Then
CmdTomaDatos.Enabled = False
txtNombreCliente.Value = "-"
TxtNombreAnteproyecto.Value = "-"
TxtNumeroAnteproyecto.Value = "-"
TxtRevision.Value = "-"
TxtFechaRevision.Value = "-"
TxtClienteFinal.Value = "-"
TxtAutor1.Value = "-"
TxtAutor2.Value = "-"
CboComentarioRevision.Value = "-"
ActiveDocument.Subdocuments.Expanded = True
CboComentarioRevision.AddItem "New"
CboComentarioRevision.AddItem "Revision"
Else
txtNombreCliente.Value = ActiveDocument.Variables("NombreCliente").Value
TxtNombreAnteproyecto.Value = ActiveDocument.Variables("NombreAnteproyecto").Value
TxtNumeroAnteproyecto.Value = ActiveDocument.Variables("NumeroAnteproyecto").Value
TxtRevision.Value = ActiveDocument.Variables("Revision").Value
TxtFechaRevision.Value = ActiveDocument.Variables("FechaRevision").Value
CboComentarioRevision.Value = ActiveDocument.Variables("ComentarioRevision").Value
TxtClienteFinal.Value = ActiveDocument.Variables("ClienteFinal").Value
TxtAutor1.Value = ActiveDocument.Variables("Autor1").Value
TxtAutor2.Value = ActiveDocument.Variables("Autor2").Value
End If
txtNombreCliente.SetFocus
End Sub




Thanks

Edited 28-Apr-06 by GeekGirlau. Reason: insert vba tags