SetFocus not working

M

magmike

I have a button that invokes code onClick and the last line of the
code ask for SetFocus on a control, but for some reason it is not
doing it - sort of. After clicking the button, I cannot find the
cursor anywhere. If I hit the TAB key, nothing happens. So then, if I
click on a blank part of the form (not on a control) then the cursor
shows up in the field that is supposed to get the focus. So it almost
as if the entire form is losing focus. Here is the code:

Private Sub ImportData_Click()
On Error Resume Next
Dim stSpec, stTable, stFileName As String
stSpec = "Prospect Import"
stTable = "Prospects"
stFileName = "C:\Documents and Settings\mkline\Desktop\import.csv"
DoCmd.TransferText acImportDelim, stSpec, stTable, stFileName
DoCmd.Requery
Me.FindCompany.SetFocus
'DoCmd.RunCommand acCmdImport
End Sub

In case it matters, this button is on a subform (Research). The parent
form is Prospects. However, the button and the control that is seeking
the focus are both on the subform.

Does anyone know what is happening here?

Thanks in advance!
magmike
 
J

John Spencer

Strange. I would think that would work

Try
Me.SetFocus
ME.FindCompany.SetFocus

Or go all out and try

Forms!MainFormName.SubFormControlName.SetFocus
Forms!MainFormName.SubformControlName.Form!FindCompany.SetFocus

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
M

magmike

Strange. I would think that would work

Try
  Me.SetFocus
  ME.FindCompany.SetFocus

Or go all out and try

   Forms!MainFormName.SubFormControlName.SetFocus
   Forms!MainFormName.SubformControlName.Form!FindCompany.SetFocus

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County



magmikewrote:





- Show quoted text -

I tried both of those and various other like-minded combinations. None
of them worked. However, I did find two things that do work. I may try
to find other ways just for the hell of it. However, the basic premise
is doing something off form.

The first (and least desirable) was adding the following:

DoCmd.Minimize
DoCmd.Maximize
Me.FindCompany.SetFocus

That works, but it is messy in that the form disappears and then
reappears.

However, the second it a lot less noticable.

I create a form that simply displays the words "One moment please..."
and then closes itself after 5 (I thought it was seconds, but it must
be way less because I barely see a blip." In the new form after
closing is where I located the instruction to set the focus on Forms!
ProsectForm!Research.Form!FindCompany

That is what I will go with for now. Thanks for your help!

magmike
 

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