Control Name argument

  • Thread starter Thread starter Gator
  • Start date Start date
G

Gator

Error telling me that the action or method needs a Control Name argument.
What does this mean? HOw do I fix it?
Sincerely
 
Gator said:
Error telling me that the action or method needs a Control Name argument.
What does this mean? HOw do I fix it?


You'd better post the code statement that is raising the error.
 
Private Sub FundNumber_LostFocus()
If IsNull(Me.FundNumber) Then
DoCmd.GoToControl (FundNumber)
End If
End Sub

I tried the code...
If IsNull(Me.FundNumber) Then
me.FundNumber.SetFocus
......but the focus does not go to that control, so I tried the code above
and got the error.
Thanks
 
DoCmd.GoToControl (FundNumber)

That's wrong. the GoToControl method requires the name of a control, as a
string. So you would write:

DoCmd.GoToControl "FundNumber"

However, calling the control's SetFocus method is better, and that does
require an object reference to the control. So this alternate code of
yours:
me.FundNumber.SetFocus

might work, if you were using it in a different event. *However*, it won't
work in the LostFocus event event of FundNumber.

There's a basic problem in what you're trying to do, if I am interpreting it
correctly. As I understand it, you want to keep the focus in FundNumber
until the user enters something in the control. Using SetFocus or
GoToControl in *any* of the control's events won't do that, because those
event's fire *before* the control has lost the focus in the first place --
yes, that's right, even the LostFocus event fires before the next control in
the tab order has gotten the focus. So setting the focus back to FundNumber
doesn't matter, because Access will then proceed to move the focus away
again.

To do what you want, you must use the control's Exit event, and have the
event procedure cancel that event if the control is Null. Like this:

'----- start of example code -----
Private Sub FundNumber_Exit(Cancel As Integer)

If IsNull(Me.FundNumber) Then
Cancel = True
End If

End Sub
'----- end of example code -----

Note, however, that even this event won't fire if the focus never goes to
the FundNumber control in the first place. It also prevents the user from
jumping around the form freely and entering information out of your
established order, and traps the user in the control when they might not
want to be.

For most purposes, I prefer to leave the business of ensuring data entry in
required controls to the form's BeforeUpdate event. That way, the user can
enter things in any order they want, so long as they get it all done before
trying to save the record. Of course, you may have a situation where the
FundNumber must be entered before anything else can be done. In such a
case, I would probably disable all the other controls initially, and then
enable them in FundNumber's AfterUpdate event, provided that FundNumber is
not Null.
 
Back
Top