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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keep focus on a form control and undo change 1

Status
Not open for further replies.

suziqueue

Programmer
May 10, 2001
26
0
0
US
I have this code on the after update event of a text box on a data entry form.

Private Sub txtPort_AfterUpdate()
Dim strNumPort As String
Dim strValPort As String
Dim strText As String

strNumPort = Me.txtPort.Value
strValPort = Me.txtValPort.Value
strText = "There are only " & Forms!frmLocation!txtValPort & " ports available for this device"

If strNumPort <= strValPort Then
Else
MsgBox strText
Me.txtPort.Undo
Me.txtPort.SetFocus
End If

End Sub

I know this should be easy and I have been searching archives and help for about 3 hours. But I cannot get the 'me.txtport.undo' and the 'me.txtPort.setfocus' to work. What in the world am I missing?

Thanks for any and all help.

Becki
 
Set the undo process in the OnGotFocus event procedure of the next control that the user tabs into from txtPort like so:

Private Sub txtNextCtrl_OnGotFocus()
Dim strNumPort As String
Dim strValPort As String
Dim strText As String

strNumPort = Me.txtPort.Value
strValPort = Me.txtValPort.Value

If strNumPort > strValPort Then
strText = &quot;There are only &quot; & Forms!frmLocation!txtValPort & &quot; ports available for this device&quot;
MsgBox strText
Me.txtPort.value = vbnullstring
Me.txtPort.SetFocus
End If

End Sub jlitondo@gatecitysteel.com
 
Thank you JLitondo, I had almost given up hope on figuring this out. I'll give it a shot.

Becki
 
depending on how your form is set up you may actually want to set that in the OnLostFocus event of txtPort jlitondo@gatecitysteel.com
 
I'll try both and see which one works best. Thanks again - hope you don't mind if I holler back at you if I get stuck. P-)
 
I've tried your suggestion on both the OnLostFocus of txtPort and on the OnGotFocus of txtLength (the next ctrl). Setting the value of txtPort to null if it is inccorrect works great both places, but I had to use DoCmd.GoToControl (&quot;txtPort&quot;) in place of Me.txtPort.SetFocus in the OnGotFocus of txtLength to keep the focus on txtPort. Thank you so much for heading me in the right direction!!!!

Becki
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top