A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

SetFocus not working



 
 
Thread Tools Display Modes
  #1  
Old October 21st, 2008, 08:48 PM posted to microsoft.public.access
magmike
external usenet poster
 
Posts: 233
Default SetFocus not working

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
  #2  
Old October 21st, 2008, 09:21 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 7,815
Default SetFocus not working

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!FindCom pany.SetFocus

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

magmike wrote:
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

  #3  
Old October 25th, 2008, 10:19 PM posted to microsoft.public.access
magmike
external usenet poster
 
Posts: 233
Default SetFocus not working

On Oct 21, 3:21*pm, John Spencer wrote:
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!FindCo mpany.SetFocus

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



magmikewrote:
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- Hide quoted text -


- 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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.