set focus to a control on a subform

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
 
D

Dirk Goldgar

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
 
R

ram

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)
 

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