An array of objects in a form

E-D

Registered User.
Local time
Today, 00:54
Joined
Dec 31, 2001
Messages
42
I want to build an array of TextBoxes on a form
so that I'll be able to go over them with the help of a
a simple for-next loop and check out if one of the fields is empty.

I can't seem to find such an option in Access

Do you have a solution ?

thanks


p.s: I'm well aware if the option "required" but I wish not to use it in this particular case.
 
Put something in the Tag property (Chk, for example) of the fields you want to check. Then loop through the fields on the form and if a field has Chk in the Tag then check its contents.
 
Chkflds returns to the calling proc the name of any textbox or combobox on a loaded form that is null or zero, starting with the control that has the lowest tab index value...

Code:
Function ChkFlds(FormName As Form) As String
Dim Msg, Title, Style
Dim ctl as Control
Dim LwstTbIndx As Single

LwstTbIndx = 1000000 ' put a million controls on a form - Good Luck!
'LwstTbIndx = lowest tab index number. Tab index may not match the sequence of the
'controls in the collection using the for each loop...
For Each ctl In FormName
    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
        If IsNull(ctl) Or ctl = "0" Then
            If ctl.TabIndex < LwstTbIndx Then
                'the empty or 0 cntrl with the lowest tabindex number is returned
                LwstTbIndx = ctl.TabIndex
                ChkFlds = ctl.Name
            End If
        End If
   End If
Next ctl

If Len(ChkFlds) <> 0 Then
    Msg = "At least one of the input fields on the form is blank or Zero." & (Chr(13) & Chr(10)) & _
          "You must fill in all the input fields (or select an item from a" & (Chr(13) & Chr(10)) & _
          "drop down list) before clicking on the 'Import' button."
    Title = "Incomplete Form..."
    Style = vbOKOnly
    MsgBox Msg, Style, Title
End If

End Function

Doug - don't forget to Dim ctl!

[This message has been edited by DALeffler (edited 01-10-2002).]
 
thank you very much!

I have learned a lot from your code
 

Users who are viewing this thread

Back
Top Bottom