Trouble with SetFocus

SteveJtoo

Registered User.
Local time
Today, 12:08
Joined
Sep 26, 2012
Messages
50
I have a datasheet form 'A' that I put Allen Browne's search box routine on. There is an ID field that gets clicked on 'A' to open a detail form 'B'. When I open form 'A' I set the 'OnActivate' event toSetFocus on the searchbox which works well. The problem I have is after I open form 'B' - do my edits etc. and close the form, I want to SetFocus back to the searchbox on form 'A'. After trying everything I could think of in events, the focus remains on the ID field that was clicked to opening form 'B'. How do I get the focus back to the search box on form 'A'? Any ideas out there??
 
Before the child form closes, it should tell the parent form which control to set focus to. Then when it closes, the proper control would have focus on the parent form already.

Code:
    strDocName = "parts"

    'Open the parts window
    DoCmd.OpenForm strDocName

    'Refresh the prior window UI to the previously selected record
    Call Forms(strDocName).Refresh_Click(ObjUIValidationPartsTbl.id)
Here the code reopens the parent form (parent form closed self when it opened child form) and fires a form event (Refresh_Click) which sets the UI to be focused on the previously selected record.

You should be able to also send the form the SetFocus event, to a particular control based on control name.

Air Code...

Code:
    strDocName = "parts"
    Call Forms(strDocName).fldpartnumber.SetFocus
 
Thanks for your quick response but I don't understand. The first form doesn't close when the other opens. Also I have tried to SetFocus on the control on the first form from the other form but not successful. Using Access 2010.
 
...but I don't understand. The first form doesn't close when the other opens.

In my example code, that is how this application works... so I am pointing out a perceived difference. It seems my perception was correct.

Also I have tried to SetFocus on the control on the first form from the other form but not successful.

That Air Code sort of example should have worked. Have you tried tracing the code using the debugger and stepped execution?

Using Access 2010.

And I develop with Access 2007. So another difference.
 
Here is the code I put on the close button on form 'B'.

Private Sub Close_Form_Btn_Click()
DoCmd.close
Dim StrDocName As String
StrDocName = "Books By Title"
Call Forms(StrDocName).txtFindAsUTypeValue.SetFocus
End Sub

It does not set the focus to the search box. it stays on the field it was on when it left. What am I doing wrong.
 
Here is the code I put on the close button on form 'B'.

Private Sub Close_Form_Btn_Click()
DoCmd.close
Dim StrDocName As String
StrDocName = "Books By Title"
Call Forms(StrDocName).txtFindAsUTypeValue.SetFocus
End Sub

It does not set the focus to the search box. it stays on the field it was on when it left. What am I doing wrong.

Looks to me like you are closing the Me form before sending the message to the parent form, no? That might be causing the trouble...
 
Ok I moved the close to after the other statements but still not working. I'm sorry that this seems like a simple problem that I should be able to fix but as you probably can tell, I'm not very good at this.
 
How about setting a break point on the red LOC:


Code:
[COLOR=Red]Private Sub Close_Form_Btn_Click()[/COLOR]
   Dim StrDocName As String
   StrDocName = "Books By Title"
   Call Forms(StrDocName).txtFindAsUTypeValue.SetFocus
   DoCmd.close
End Sub

Perform stepped execution of this code (F8), and watch to make sure the txtFindAsUTypeValue control actually receives focus when the SetFocus Event is executed.
 
To mdlueck. I did as you said and each step is hit but still not working??

To boblarson. I changed it back as you said but still not working.
 
To mdlueck. I did as you said and each step is hit but still not working??

Just a wild guess... this control does not happen to be on a subform of the form, does it? There is an alternate syntax needed if the target control is actually on a subform of the form:

Code:
'As this form is used within a subform control, necessary to setfocus
'to the subform control first, then the control itself which is on the subform form
Me.Parent.subform_metooling_gaging.SetFocus
Me.fldid.SetFocus

So in that way, you would also need two SetFocus LOCs.
 
There are only two forms 'A' is the datasheet and 'B' opens when I click the ID field of 'A'. I am clicking a close button on 'B' and want the focus set to the search box on the datasheet 'A'. It seems so simple yet ???
 
Well thanks for that. Now I'm only crazy - not dumb. Maybe it has something to do with the search routine or maybe because the datasheet is not editable?? I will check it out & let you know. Thanks for all the time you have spent.
 
I was wrong and right. Changing to editable (really Data Entry = Yes because it was always editable) didn't change anything except not showing any data(??), BUT when I SetFocus to another control it worked!! It's either something with the search (although I am able to set focus to it when form 'A' opens). Could it be because it's a split form but not really a split form and the search box is in the form header. The form is a split form only so I can have a header with a datasheet on the same form. (I learned that from someone else!)??
 

Users who are viewing this thread

Back
Top Bottom