setfocus to control in visible subform

D

Davo78

Hi All,

I have a from "Input" which has a subform "Variations" which is not visible.
I make it visible with a toggle button and close it with Do Cmd Close and
goto macro (the next control of form "Input") in the "AfterUpdate" of the
comments control box, this works fine but the problem that I have is that the
subform does not take focus until I mouse click on the subform, then the
focus is set to the correct control box (VariationCode).

Is there a way of setting focus to the first control box (VariationCode) in
the subform "Variations" without using the mouse.

I have tried using the goto and setfocus commands but to no use.

Thanks in Advance

Davo78
 
L

Linq Adams via AccessMonster.com

The syntax would be

Me!YourSubformControlName.Form!VariationCode.SetFocus

Now if

your subform ***Control Name*** is actually

"Variations"

then your code would be

Me!Variations.Form!VariationCode.SetFocus
 
D

Davo78

Ling
Thank you for your prompt reply.

Please excuse my ignorance but where would I place this syntax
in the toggle click() string or elswere.

I have been compiling my DB using books and asking questions and at times
not upto speed.

Thanks Again
Davo78
 
L

Linq Adams via AccessMonster.com

From what you've said, I'd place it directly after the code in the toggle on
click event that makes the subform visible.
 
D

Davo78

Ling

I have tried placing the syntax in the toggle click event as you suggested,
but still cannot get it to work.

below is the toggle click event is this correct.

The main form is "Input" the subform is "Variations" and the control (in
subform Variations) to have focus is "VariationsCode"

Private Sub ToggleVariations_Click()

If Me![ToggleVariations].Caption = "Variations" Then
Me![Variations].Visible = False
Me![Variations].Visible = True
Me![ToggleVariations].Caption = "Variations Close"
Else
Me![Variations].Visible = True
Me![Variations].Visible = False
Me![ToggleVariations].Caption = "Variations"
End If

Me!Variations.Form!VariationCode.SetFocus

End Sub

Thanks for the help

Davo78
 
L

Linq Adams via AccessMonster.com

That would have you trying to set focus to VariationCode whether the subform
was visible or not, which I think will pop an error. You only want to set the
focus ***if the subform is visible***

I'm also confused as to why you set the visibility one way and then
immediately change it. Logically, your code should be:

Private Sub ToggleVariations_Click()

If Me![ToggleVariations].Caption = "Variations" Then
Me![Variations].Visible = True
Me![ToggleVariations].Caption = "Variations Close"
Me!Variations.Form!VariationCode.SetFocus
Else
Me![Variations].Visible = False
Me![ToggleVariations].Caption = "Variations"
End If

End Sub
 
L

Linq Adams via AccessMonster.com

Sorry, left out a line before I pasted the code on the last post. Should be:

Private Sub ToggleVariations_Click()

If Me![ToggleVariations].Caption = "Variations" Then
Me![Variations].Visible = True
Me![ToggleVariations].Caption = "Variations Close"
Me![Variations].SetFocus
Me![Variations].Form!VariationCode.SetFocus
Else
Me![Variations].Visible = False
Me![ToggleVariations].Caption = "Variations"
End If

End Sub

BTW, does the subform appear and disappear as you anticipated it would?
 
D

Davo78

Ling,

Thankyou for your replies

I now have this working fine, but, another question if I may, is there a way
of closing this subform programmably after update then goto the next control
"ToggleTravel".

Since getting the setfocus to work I have been trying to achieve this.

Thanks again for your help
Davo
 

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