Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setfocus afterupdate event question

Status
Not open for further replies.

Ktx7ca

IS-IT--Management
Apr 5, 2008
88
CA
Hello all

I have a textbox(entryID) that when you enter a number the code in the afterupdate event checks to see if it's valid and adds it to a table

At the end of this process I want the cursor to be back in the textbox ready for the next entry.

I have tried several ways and locations of the setfocus command but it never returns to the text box and I don't get any error messages. I can tab to back to the box and of course reclick it with mouse no problem

any ideas why
 
Yes I agree with you and thats what I have and it is the last line of code.

you can see why it's driving me crazy
 
How are ya Ktx7ca . . .

Post the code! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I have removed all the code except for this and it still dosn't work

Private Sub EntryID_AfterUpdate()
Me.EntryID = ""
Me.EntryID.SetFocus
End Sub
 
It runs the code fine but as soon as I press enter it moves to the next tab order and does not do the set focus.
 
Ktx7ca . . .

Set focus to another control first, then back to EntryID.
Code:
[blue]   Me.EntryID = ""
   Me![purple][B][I]AnyOtherTextboxName[/I][/B][/purple].SetFocus
   Me.EntryID.SetFocus[/blue]
Realize you'll never successfully enter any data with the code you've provided!

[blue]Your Thoughts . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I have tried that a few times and just tried did again, but no luck.

Maybe there's something wrong with the form. I think I'll try creating a new one

It's very strange

Yes I do know that I don't enter any data with the code, this problem is so strange I took it out to make therer was'nt the slighest posability of some conflidt.

But thanks for pointing that out, as you never know
 
You could always put the setfocus code on the Lost Focus or On Exit event. That would, however, create logic that would not allow the user to move to another field. You would need to create an If statement on the LostFocus event that allowed the user to move on if certain criteria were met. For example, if the field is blank and the user is allowed to go another field you could use the following code:

Code:
If Not IsNull(Me.EntryID) Then
   Me.EntryID.SetFocus
End If

Brenda
 
Ktx7ca . . .

I've been thru this before with other events ([blue]On Exit, On Lost Focus[/blue]) and it appears the best thing to do is to let the event ([blue]AfterUpdate[/blue] in this case) complete. I offer the following work around in case you still meet dead ends. [blue]The technique uses the timer to allow the event (AfterUpdate) to complete[/blue] and executes the code you'd normally have in the AfterUpdate event.
[ol][li]In the controls [blue]AfterUpdate[/blue] event, copy/paste the following:
Code:
[blue]   Me!Name = Null
   Me.TimerInterval = 10 [green]'Allow AfterUpdate to complete.[/green][/blue]
[/li]
[li]In the forms [blue]On Timer[/blue] event, copy/paste the following:
Code:
[blue]   Me!Name.SetFocus
   Me.TimerInterval = 0[/blue]
[/li][/ol]
Do your testing! [thumbsup2)

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top