Grimwadec said:
Once a user populates the first control in the Form's Tab order, some
subsequent controls are automatically populated and others aren't
depending
on what is populated in the first control. I then want to go to the next
control in the tab order, if that is control has been automatically
populated then go the next control etc. etc. until it finds a control that
has not been automatically populated and stop there so the user can then
enter data. In that way the user doesn't have to bother with the form
stopping at controls that are already populated.
As I said, I can simply run individual code On Got Focus in each control
which would then tell it to go to the next control if the control with the
focus is populated but I was trying to get by with just the one looping
function but I guess I can just run the NextControl Function on Got Focus
on
each control
I would certainly not do it that way. I'd use the first control's
AfterUpdate event to do whatever it is that populates the other controls,
and then call a function like this:
'------ start of code ------
Function GoToNextNullControl()
' Set the focus to the next Null control in the tab order.
' Ignore all non-data controls (which don't have a Value
' property).
'
' Copyright (c) 2009, DataGnostics LLC
' License is granted to use this code in your application,
' provided the copyright notice remains intact.
Dim objParent As Object
Dim ctl As Access.Control
Dim strStartControl As String
Dim strNextControl As String
Dim blnControlIsNull As Boolean
Dim lngControlCount As Long
Set ctl = Screen.ActiveControl
Set objParent = ctl.Parent
strStartControl = ctl.Name
strNextControl = NextInTabOrder(ctl)
' Loop through the controls in tab order, looking
' for one that has a Null value.
Do Until strNextControl = strStartControl
' Check to see if we've gotten into an infinite
' loop, which could happen if the starting control
' is not in the tab order.
lngControlCount = lngControlCount + 1
If lngControlCount > objParent.Controls.Count Then
Exit Function
End If
' Point ctl to the next control.
Set ctl = objParent.Controls(strNextControl)
' Check to see if this control has a Null value.
' If it doesn't have a Value property at all,
' treat that as "not null".
blnControlIsNull = False
On Error Resume Next ' Suspend normal error-handling
blnControlIsNull = IsNull(ctl.Value)
On Error GoTo 0 ' Resume normal error-handling
' If the control has a Null value, exit the loop.
If blnControlIsNull Then
Exit Do
End If
' Locate the next control in the tab order.
strNextControl = NextInTabOrder(ctl)
Loop
' If we found a non-null control, set the focus to it.
If blnControlIsNull Then
ctl.SetFocus
End If
Set ctl = Nothing
Set objParent = Nothing
End Function
'------ end of code ------
That hasn't really been tested, but it may work.