Set focus not working properly

J

JenK

I have a find button. it is coded as such

Private Sub Search_Click()
On Error GoTo Err_Search_Click
Me.TrackingNum.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_Search_Click:
Exit Sub
Err_Search_Click:
MsgBox Err.Description
Resume Exit_Search_Click
End Sub

For some reason everytime I select the find button instead of focusing the
search on the [TrackingNum] field its focus is on the form. I am not sure why
it is doing this. It is doing the same thing on other forms as well and they
are all coded the same way. Any ideas on what the problem may be?
 
A

Allen Browne

Does it make any difference if you swap the 2 lines around, i.e. place the
SetFocus line after the doMenuItem?
 
J

JenK

I tried that but then it doesn't search any particular field (it blacks out
the search field box)

Allen Browne said:
Does it make any difference if you swap the 2 lines around, i.e. place the
SetFocus line after the doMenuItem?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

JenK said:
I have a find button. it is coded as such

Private Sub Search_Click()
On Error GoTo Err_Search_Click
Me.TrackingNum.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_Search_Click:
Exit Sub
Err_Search_Click:
MsgBox Err.Description
Resume Exit_Search_Click
End Sub

For some reason everytime I select the find button instead of focusing the
search on the [TrackingNum] field its focus is on the form. I am not sure
why
it is doing this. It is doing the same thing on other forms as well and
they
are all coded the same way. Any ideas on what the problem may be?
 
A

Allen Browne

So you want to open the Find dialog, with the focus in the TrackingNum
field.

See if this works for you:
Me.TrackingNum.SetFocus
RunCommand acCmdFind

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

JenK said:
I tried that but then it doesn't search any particular field (it blacks out
the search field box)

Allen Browne said:
Does it make any difference if you swap the 2 lines around, i.e. place
the
SetFocus line after the doMenuItem?

JenK said:
I have a find button. it is coded as such

Private Sub Search_Click()
On Error GoTo Err_Search_Click
Me.TrackingNum.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_Search_Click:
Exit Sub
Err_Search_Click:
MsgBox Err.Description
Resume Exit_Search_Click
End Sub

For some reason everytime I select the find button instead of focusing
the
search on the [TrackingNum] field its focus is on the form. I am not
sure
why
it is doing this. It is doing the same thing on other forms as well and
they
are all coded the same way. Any ideas on what the problem may be?
 

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