Bueno esta funcion la hice pensando en que a veces uno necesita saber si en un form, hay un text vacio o n combobox sin que le seleccionen un dato, oque no hayan seleccionado ningun checkbox, te devuelve true si algun control le falta algo y le da el foco, y te devuelve false cuando ya esta todo completo
Espero que sirva, ademas de que pueden seleccionar opcionalmente los controles que necesiten, TextBox, Combobox y CheckBox, si se me pasa uno por ahi importante o mas bien usual diganmelo y lo agrego...
y asi lo llamas asiCódigo:Public Function Controles_Vacios(fForm As Form, Optional cText As Boolean = True, Optional cCombo As Boolean = True, Optional cCheck As Boolean = True) As Boolean Dim xControl As Object Dim i As Integer, iVal As Integer, barray() As Boolean i = -1 For Each xControl In fForm.Controls If cText = True Then If TypeOf xControl Is TextBox Then If xControl.Text = "" Then Controles_Vacios = True xControl.SetFocus Exit Function End If End If End If If cCombo = True Then If TypeOf xControl Is ComboBox Then If xControl.ListIndex = -1 Then Controles_Vacios = True xControl.SetFocus Exit Function End If End If End If If cCheck = True Then If TypeOf xControl Is CheckBox Then i = i + 1 ReDim Preserve barray(i) barray(i) = xControl.Value End If End If Next If cCheck = True Then If i <> -1 Then For i = 0 To UBound(barray) iVal = iVal + CInt(barray(i)) Next End If End If If i = -1 Then Controles_Vacios = False Else If iVal <> 0 Then Controles_Vacios = False Else Controles_Vacios = True End If End If End Function
Código:Private Sub Command1_Click() If Controles_Vacios(Me) = True Then MsgBox "Te falta Algun Campo" Else MsgBox "Todo Correcto" End If End Sub