Set focus not working properly

  • Thread starter Thread starter JenK
  • Start date Start date
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?
 
Does it make any difference if you swap the 2 lines around, i.e. place the
SetFocus line after the doMenuItem?
 
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?
 
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?
 
Back
Top