setfocus back to control onexit

C

Chace

Conceptually here is what I want to achieve:

Unbound text box located above a list box.
User types a value in the text box and hits enter.
Value in the text box is added to the list in the list box and the text box
is set to Null.
~problem occurrs below~
Set focus back to text box, ready for the user to type another value in the
text box to add to the list box. However, I cannot seem to get the setfocus
to work as I need it to.

I read in another posting to use the OnExit event of the text box and set
the Cancel Argument to TRUE in order to set the focus back to the text box.
This works fine, but it will never let me click on any other controls on the
form, which I need to be able to do. Setting the Cancel Argument to FALSE
doesn't work at all.

Any ideas on how to accomplish what I need? Thanks in advance.
 
D

Dale Fye

Try the textbox AfterUpdate event instead of the Exit or LostFocus event.
Assuming that the RowSource for your listbox is a value list, you should be
able to do something like:

Private Sub txt_AddToList_AfterUpdate

me.lst_YourList.RowSource = me.lst_YourList.RowSource & ";" & me.txt_AddToList
me.txt_AddToList = NULL
me.txt_AddToList.setfocus

End Sub

By setting the value of the textbox to Null, you ensure that the AfterUpdate
event will not fire if it is still empty when you tab out of it, or click on
another control.

HTH
Dale
 
C

Chace

Dale,

I could not get it to work in my specific case. The list box gets the focus
and keeps it. I even added a new text box control and list box control and
used your code exactly as it is below and the same result occurs.....the list
box gets the focus at the end of execution. Any other ideas?

Chace
 
C

Chace

FYI, This is how I fixed it the problem to get the functionality I needed:

in the OnExit event of the textbox I put the following code:

Private Sub txt_LotNum_Exit(Cancel As Integer)
If Not IsNull(Me.txt_LotNum) Then Cancel = True
Me.txt_LotNum = Null
End Sub

Hope it can help someone else.
Chace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top