Hi guys,
for an if statement i want to see if all the fields of a form are empty. Is there an easy way to do it instead of checking every field separately.
Hi guys,
for an if statement i want to see if all the fields of a form are empty. Is there an easy way to do it instead of checking every field separately.
None that I know.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
You could iterate the controls using a for each statement.
Iterative or not, still checking content of each field/control. Iterative code is just more compact. Relies on some common feature of the controls because probably want to ignore labels and subforms if any.
If the controls have a similar naming structure, like Data1, Data2, Data3, etc. and you have say 10 controls to check:
booEmpty As Boolean
For i = 1 to 10
If IsNull(Me.Controls("Data" & i)) Then booEmpty = True
Next
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Perhaps if you could give us an idea of your actual goal, here, we could give you a better answer. For a starter, why are you checking whether or not all Controls are unpopulated? Also, is this a bound Form?
Linq ;0)>
I agree with Linq that more insight is needed to provide the best solution.
That's kinda what I was thinking only using the Form's collection vs. a strongly typed approach. So something like....
The above If Then statement could be nested within another If Then or Case Select. You could verify the control type using something likeCode:Dim ctl as Control For Each ctl In Me.Controls 'Change the backcolor If IsNull(ctl.Value) Then Ctl.Backcolor = 255 End If Next ctl
If ctl.ControlType = acTextbox Then
Another approach I use is to employ the Tag property of controls on my forms. So I will place keywords in the Tag property for controls that I want to treat similarly. The following example shows how I display multiple labels, but not all labels, on a form.
Code:Dim ctl as Control For Each ctl In Me.Controls 'Show the asterisk If InStr(ctl.Tag, "Asterisk") <> 0 Then ctl.Visible = True End If Next ctl