set focus to a control on a subform

  • Thread starter Thread starter ram
  • Start date Start date
R

ram

Hi All,
I am asking for help with the code shown below. The setfocus at the end of
the code is not working.

i would like the code to remove the value just entered when it is over the
limit and have the focus stay on the csorent text box, so that a new value
can be entered.

Thanks in advance for any help



Private Sub CSORent_Exit(Cancel As Integer)
If Me.CSORent > Forms!START!qryActiveAgents!Availablecso Then
MsgBox (FormatCurrency((Me.Text29 -
Forms!START!qryActiveAgents!Availablecso)) & (" over cso limit"))
Me.ActiveControl = 0
Me.CSORent.SetFocus
 
ram said:
Hi All,
I am asking for help with the code shown below. The setfocus at the end of
the code is not working.

i would like the code to remove the value just entered when it is over the
limit and have the focus stay on the csorent text box, so that a new value
can be entered.

Thanks in advance for any help



Private Sub CSORent_Exit(Cancel As Integer)
If Me.CSORent > Forms!START!qryActiveAgents!Availablecso Then
MsgBox (FormatCurrency((Me.Text29 -
Forms!START!qryActiveAgents!Availablecso)) & (" over cso limit"))
Me.ActiveControl = 0
Me.CSORent.SetFocus


Since this is in the Exit event of the control you want to keep the focus
in, just set the event procedure's Cancel property to True:

Private Sub CSORent_Exit(Cancel As Integer)

If Me.CSORent > Forms!START!qryActiveAgents!Availablecso Then

MsgBox FormatCurrency((Me.Text29 - _
Forms!START!qryActiveAgents!Availablecso) & _
" over cso limit"

Me.ActiveControl = 0
'SHOULDN'T THIS JUST BE Me.CSORent = 0

Cancel = True

End If

End Sub
 
Thank you, It was Just what I needed.



Dirk Goldgar said:
Since this is in the Exit event of the control you want to keep the focus
in, just set the event procedure's Cancel property to True:

Private Sub CSORent_Exit(Cancel As Integer)

If Me.CSORent > Forms!START!qryActiveAgents!Availablecso Then

MsgBox FormatCurrency((Me.Text29 - _
Forms!START!qryActiveAgents!Availablecso) & _
" over cso limit"

Me.ActiveControl = 0
'SHOULDN'T THIS JUST BE Me.CSORent = 0

Cancel = True

End If

End Sub

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top