control properties

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?
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top