Full Version: SetFocus to a control
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
zero_cool
Hey everybody,
I have a IF function that runs on my form. After END IF I have the command Me.PeriodFrom.SetFocus

When the code runs however, the focus is not returned to this control and instead passes to the next one in the tab list. Is there some rule about where the setfocus command must be placed that I don't know about?

Thanks in advance.
freakazeud
Hi,
what code are you using. Where are you fireing it, where is the focus at that moment, where do you want the focus to go to...
Maybe you can clarify those things so we get a better idea of what it is you are trying to achieve.
HTH
Good luck
zero_cool
Private Sub PeriodFrom_LostFocus()

If IsNull(Me.ExpenseID) = True Then
MsgBox ("You must enter a Period From date before proceeding")
End If

Me.PeriodFrom.SetFocus

End Sub

That is an extract of the code which should answer most of your questions. I did have Me.PeriodFrom.SetFocus within the IF function. I was moving it around to try and understand what the best sequence was.
JayNoelOlimpo
Hi;

Use Before Update Event procedure ...

CODE
If IsNull(ExpenseID) Then
    MsgBox ("You must enter a Period From date before proceeding")
    Cancel = True
End If


HTW.
zero_cool
Hi,
I tired entering that code and it did not really do what i wanted it to.

I have a mainform (with the ExpenseID on) and a subform. When the user enters a date (in Period From) the expense ID is generated. If they move into the subform without a expense ID being generated then it generates an error because there is no link. I want to prevent that by not letting the focus move from the Period From box until a date has been entered.

Hope that makes sense.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.