control properties

  • Thread starter Thread starter Abrm
  • Start date Start date
A

Abrm

hi,

I my form I would like to check if all visible fields are filled, a
completeness check
I have many controls on my form, but I only want to check the controls that
are visble.

How do I read the value for the "visible" property of a control?
 
Me![NameOfControl].Visible

However, I don't think you're going to be able to get away with just looping
through the Controls collection, because labels and command buttons are both
controls, and presumably you'll have some of them visible as well...

Maybe something like:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctlCurr As Control
Dim strMessage As String

For Each ctlCurr In Me.Controls
Select Case ctlCurr.Type
Case acCheckBox, acOptionGroup, acTextBox, acComboBox
If ctlCurr.Visible And (Len(ctlCurr & vbNullString) = 0) Then
strMessage = strMessage & ctlCurr.Name & vbCrLf
End If
Case acListBox
If ctlCurr.Visible And (ctlCurr.ItemsSelected.Count = 0) Then
strMessage = strMessage & ctlCurr.Name & vbCrLf
End If
End Select
Next ctlCurr

If Len(strMessage) > 0 Then
Cancel = True
MsgBox "The following controls need to have values:" & vbCrLf & _
strMessage, vbOkOnly + vbCritical
End If

End Sub
 
Back
Top