Shift focus off command button

  • Thread starter Thread starter Starry
  • Start date Start date
S

Starry

Hi

No matter what I cannot seem to get a subform field (or any control on the
parent form for that matter) to take the focus after clicking a cmdbutton (I
am doing this from code ie Me.whatever.setfocus . I am using an onclick
event.) A TAB or mouse click is required to shift the focus on.

The command buttons perform operations on the subform.

No doubt I'm tired and being a little dumb but I have never had an issue
between other controls.

Any ideas?
 
Starry said:
No matter what I cannot seem to get a subform field (or any control on the
parent form for that matter) to take the focus after clicking a cmdbutton (I
am doing this from code ie Me.whatever.setfocus . I am using an onclick
event.) A TAB or mouse click is required to shift the focus on.

The command buttons perform operations on the subform.

No doubt I'm tired and being a little dumb but I have never had an issue
between other controls.


Using code in a button's Click event to change the focus to
a different visible, enabled control on the same form should
not be a problem.

The devil is in the details ;-)
 
Thanks Marsh I have already tried many tests (see Text222 below) without a
result. I think the problem may be higher up so I'll explain. This is very
ugly but I needed a quick fix to limit user access until all my security is
setup which will be months away.

cmdNewjob unlocks a critical field and turns the subform (Jobs) into a type
of dataentry mode. The cmdConfirm then flips it back but shift the focus I
cannot. If I specify a subform control the command is ignored and if I
specify my test (or another mainform control) I get a 2110 'cannot move the
focus to control......'

I have tried shifting it up down and into other events.

Private Sub cmdConfirm_Click()
cmdEditTypes.Enabled = True
cmdNew.Enabled = True
Me.Jobs.Form.FilterOn = False
Me.Text222.SetFocus 'focus test control
'[Jobs]!txtJobNumber.SetFocus
'[Jobs]!txtJobNumber.Locked = True


Private Sub cmdNewjob_Click()
[Jobs]!txtJobNumber.Locked = False
cmdEditTypes.Enabled = False
cmdNew.Enabled = False
Me.Jobs.Form.Filter = IsNull(txtJobNumber)
Me.Jobs.Form.FilterOn = True
DoCmd.GoToRecord , , acNewRec
Me.Jobs.Form.txtJobNumber.SetFocus
 
I have tidied this up a bit and added an extra prefocus (just thought I'd
try!) to the main form but same problems

Private Sub cmdConfirm_Click()
cmdEditTypes.Enabled = True
cmdNew.Enabled = True
Me.Jobs.Form.DataEntry = False
Me.SetFocus
Me.Text222.SetFocus 'focus test control
'[Jobs]!txtJobNumber.SetFocus
'[Jobs]!txtJobNumber.Locked = True

Private Sub cmdNewjob_Click()
Me.Jobs.Form.txtJobNumber.Locked = False
cmdEditTypes.Enabled = False
cmdNew.Enabled = False
Me.Jobs.Form.DataEntry = True
Me.SetFocus
Me.Jobs.Form.txtJobNumber.SetFocus

Starry said:
Thanks Marsh I have already tried many tests (see Text222 below) without a
result. I think the problem may be higher up so I'll explain. This is very
ugly but I needed a quick fix to limit user access until all my security
is setup which will be months away.

cmdNewjob unlocks a critical field and turns the subform (Jobs) into a
type of dataentry mode. The cmdConfirm then flips it back but shift the
focus I cannot. If I specify a subform control the command is ignored and
if I specify my test (or another mainform control) I get a 2110 'cannot
move the focus to control......'

I have tried shifting it up down and into other events.

Private Sub cmdConfirm_Click()
cmdEditTypes.Enabled = True
cmdNew.Enabled = True
Me.Jobs.Form.FilterOn = False
Me.Text222.SetFocus 'focus test control
'[Jobs]!txtJobNumber.SetFocus
'[Jobs]!txtJobNumber.Locked = True


Private Sub cmdNewjob_Click()
[Jobs]!txtJobNumber.Locked = False
cmdEditTypes.Enabled = False
cmdNew.Enabled = False
Me.Jobs.Form.Filter = IsNull(txtJobNumber)
Me.Jobs.Form.FilterOn = True
DoCmd.GoToRecord , , acNewRec
Me.Jobs.Form.txtJobNumber.SetFocus
 
Starry said:
I have tidied this up a bit and added an extra prefocus (just thought I'd
try!) to the main form but same problems

Private Sub cmdConfirm_Click()
cmdEditTypes.Enabled = True
cmdNew.Enabled = True
Me.Jobs.Form.DataEntry = False
Me.SetFocus
Me.Text222.SetFocus 'focus test control
'[Jobs]!txtJobNumber.SetFocus
'[Jobs]!txtJobNumber.Locked = True

Private Sub cmdNewjob_Click()
Me.Jobs.Form.txtJobNumber.Locked = False
cmdEditTypes.Enabled = False
cmdNew.Enabled = False
Me.Jobs.Form.DataEntry = True
Me.SetFocus
Me.Jobs.Form.txtJobNumber.SetFocus

Starry said:
Thanks Marsh I have already tried many tests (see Text222 below) without a
result. I think the problem may be higher up so I'll explain. This is very
ugly but I needed a quick fix to limit user access until all my security
is setup which will be months away.

cmdNewjob unlocks a critical field and turns the subform (Jobs) into a
type of dataentry mode. The cmdConfirm then flips it back but shift the
focus I cannot. If I specify a subform control the command is ignored and
if I specify my test (or another mainform control) I get a 2110 'cannot
move the focus to control......'


If the buttons are on the main form, then the main form
already has the focus.

To move the focus from the main form to a control on a
subform, you should first set the focus to the subform
control.
. . .
Me.Jobs.Form.DataEntry = True
Me.Jobs.SetFocus
Me.Jobs.Form.txtJobNumber.SetFocus

Other than that, the logic seems ok.

Double check the the target control is both visible and
enabled. If you can't get any further, try commenting out
lines of code until something works, then uncomment them one
at a time until you find the offending line.
 

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

Back
Top