Refer to all fields in a form

Krysti

Registered User.
Local time
Today, 09:54
Joined
Sep 20, 2002
Messages
40
Hi there,

This may be a stupid question, but... is there a way to refer to all fields, in a form, in code?

For example, I have a form and I want to write code that says if all the fields that are enabled are not null, then...blah blah blah. Is this possible?

Example:

If AllFields.Enabled = True And Not IsNull(AllFields.Value) Then
blah blah blah
End If


Thanks!! :D

Krysti
 
Last edited:
Yep, use a loop. Paste these functions into a blank module.

Code:
Function fnAllControlsEnabled(frm as form)

Dim ctl As Control, frm as form, intCtlCount as integer, intEnCount as integer

For Each ctl In frm.Controls

if ctl.enabled = true then
intEnCount = intEnCount + 1
end if
intCtlcount = intCtlcount+1
next ctl

If intCtlCount = intEnCount then
fnAllControlsEnabled = true 
else: fnAllControlsEnabled = false
end if

end function

Function fnAnyNullControls(frm as form)

Dim ctl As Control, frm as form, intCtlCount as integer, intNotNull as integer

For Each ctl In frm.Controls

if not isnull(ctl.value) then
intNotNull = intNotNull + 1
end if
intCtlcount = intCtlcount+1
next ctl

If intCtlCount = intNotNull then
fnAnyNullControls = False 
else: fnAnyNullControls = True
end if

end function

where you want to check the form,

Code:
If fnAllControlsEnabled(Form) = True And fnAnyNullControls(form) = false Then 
blah blah blah 
End If
 
Hi Chief,

Thanks for the reply. I'm having problems with the code you gave me for some reason...it's driving me crazy. I know how to write some code, but am not all that knowledgeable. The error I'm getting is "Object doesn't support this property or method". It looks like "ctl.Enabled = True" is the problem. Why would I not be able to refer to a control being enabled? Makes no sense to me...

Help :confused:

Thanks,

Krysti
 
Try

ctl.[Enabled] = True

instead.

I think that will work.

RichM
 
Either way, I'm getting an error now that says Method or Data Member not found. Enabled is not one of the options when I type ctl.

The only options I have are:

Application
Count
Item
Parent

Ugh! :mad:

Krysti
 
As some controls (such as labels) may not have an Enabled property, I think you should also check their control types e.g.

Code:
If ctl.ControlType = [b]acTextBox[/b] Or ctl.ControlType = [b]acXxxx[/b] Then
   If ctl.Enabled = True Then
     .........
     .........
 
Good point EMP, forgot about that:o
 
I looked at some old code I use for locking and unlocking controls.

In the loop that goes through the controls collection, I think you need something like

Set ctl = frm.Controls(index)

before you refer to a property of the variable "ctl".

RichM
 
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "A" Then
If IsNull(Me.Pd) Then
End If
If Me.Pd = True Then
ctl.Locked = True
ctl.Enabled = False
Else
ctl.Enabled = True
ctl.Locked = False
End If
End If


Next
 

Users who are viewing this thread

Back
Top Bottom