form focus

S

smk23

I have a form that is loaded but invisible until called. When I make the form
visible, I would like to run some code. If "frm" is set as the form being
called, I have these lines:

frm.Visible = True
frm.SetFocus

I tried putting the code on the "Got Focus" event of frm with no results.
Where should I put the code that needs to run every time the form is visible?
Thanks!!
 
M

Marshall Barton

smk23 said:
I have a form that is loaded but invisible until called. When I make the form
visible, I would like to run some code. If "frm" is set as the form being
called, I have these lines:

frm.Visible = True
frm.SetFocus

I tried putting the code on the "Got Focus" event of frm with no results.
Where should I put the code that needs to run every time the form is visible?


How about putting all your visible process into a public sub
procedure in the form's module:

Public Sub DoVisible()
Me.Visible = True
' all the other stuff you want to do
. . .
EndSub

Then you could call it from anywhere using:

frm.DoVisible
 
L

Linq Adams via AccessMonster.com

The reason, from Access Help:
If a form contains controls for which the Enabled property is set to True,
you can't move the focus to the form itself. You can only move the focus to
controls on the form. In this case, if you try to use SetFocus to move the
focus to a form, the focus is set to the control on the form that last
received the focus.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
S

Stuart McCall

smk23 said:
I have a form that is loaded but invisible until called. When I make the
form
visible, I would like to run some code. If "frm" is set as the form being
called, I have these lines:

frm.Visible = True
frm.SetFocus

I tried putting the code on the "Got Focus" event of frm with no results.
Where should I put the code that needs to run every time the form is
visible?
Thanks!!

I think you ought to be able to use the form's Activate event.
 
G

geppo

Ciao said:
I have a form that is loaded but invisible until called. When I make
the form visible, I would like to run some code. If "frm" is set as
the form being called, I have these lines:

frm.Visible = True
frm.SetFocus

I tried putting the code on the "Got Focus" event of frm with no
results. Where should I put the code that needs to run every time the
form is visible? Thanks!!


qui:

private sub form_activate()

..........................
.....................
.....................

end sub
 
M

Marshall Barton

Linq said:
The reason, from Access Help:
If a form contains controls for which the Enabled property is set to True,
you can't move the focus to the form itself. You can only move the focus to
controls on the form. In this case, if you try to use SetFocus to move the
focus to a form, the focus is set to the control on the form that last
received the focus.


True, but irrelevant.

If there is an enabled control, setting the focus to the
form will set it to the active control in any case. Either
way the form is visible and active.
 

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