Vba strategy required

arage

Registered User.
Local time
Today, 14:04
Joined
Dec 30, 2000
Messages
537
Hi,
I’d like to be able to “scan” or view all the controls on a form & pick up the first blank one I encounter. I need a loop so that after my message box appears, the loop will continue looking for other blank controls and give messages for them. Only when the form doesn’t have blank controls will the loop exit.

I’m just having problems getting an idea on how I can properly start my loop from 1 control and then jump to the next control on the form…

Maybe I should be utilizing the tab index for this? I dunno…
 
Hi arage,
you need a for each loop like

Dim ctl As Control
Dim frm As Form

Set frm = Me

For Each ctl In frm
If ctl.ControlType = acTextBox Then
'check for nulls/empties
'do whatever you wanna do
End If
Next

if you have other types of boxes you may want to use
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox or ...

it's probably easiest to fire this off when your user tries to close the form or move to a different record. You could then let the loop run and fire up an MsgBox for each empty control, but it might be nicer - to avoid displaying 20 errors at one time - to just show the first, step out of the loop and then use me.BlankControl.SetFocus to take the user there so they can fix it. They can then try again and get the next message etc etc.

HTH
Drew
 

Users who are viewing this thread

Back
Top Bottom