I need help with synch 2 forms

A

Al

I have two forms that are exactly similar both have tabbed pages. Let us say
that they are From1 and Form2. I want to open From2 from Form1 and set focus
on the same control that has the focus in Form1. Is there a way?
thanks
 
M

Marshall Barton

Al said:
I have two forms that are exactly similar both have tabbed pages. Let us say
that they are From1 and Form2. I want to open From2 from Form1 and set focus
on the same control that has the focus in Form1. Is there a way?

If the two controls have the same name, try using:

DoCmd.OpenForm "Form2"
Forms!Form2(Me.ActiveControl.Name).SetFocus

If there is a timing problem where form2 is not yet ready to
set the focus, then you will have to tell Form2 to set the
focus:

DoCmd.OpenForm "Form2", OpenArgs:= Me.ActiveControl.Name

Then, in form2's Load event procedure:

If Not IsNull(Me.OpenArgs) Then
Me(Me.OpenArgs).SetFocus
End If
 
A

Al

Thank you Marshall,
Only one problem using the ".ActiveControl" is that when I open Form2 I open
it from Form1 by clicking a command button called "cmdAudit", hence, the
command button will always have the focus, therefore I get an error message
saying that It can not find cmdAudit control on Form2 and this is due to the
fact that I do not have this control on Form2. Because of that,
".ActiveControl" is going to be a problem. That is why this is tricky. The
user wants to be working, say, in text boxe on tab "Page3" and when they
click on the cmdAudit button they want Form2 to open on tab Page3 and so on.
Do you think that is possible?
thanks
 
M

Marshall Barton

You could try using Screen.PreviousControl instead of
Me.ActiveControl

OTOH, I sometimes use the DoubleClick event on individual
controls instead of a separate button. There's slightly
less UI clutter and it doesn't move the focus.
 
A

Al

Yes, it works, thank you

Marshall Barton said:
You could try using Screen.PreviousControl instead of
Me.ActiveControl

OTOH, I sometimes use the DoubleClick event on individual
controls instead of a separate button. There's slightly
less UI clutter and it doesn't move the focus.
--
Marsh
MVP [MS Access]

Only one problem using the ".ActiveControl" is that when I open Form2 I open
it from Form1 by clicking a command button called "cmdAudit", hence, the
command button will always have the focus, therefore I get an error message
saying that It can not find cmdAudit control on Form2 and this is due to the
fact that I do not have this control on Form2. Because of that,
".ActiveControl" is going to be a problem. That is why this is tricky. The
user wants to be working, say, in text boxe on tab "Page3" and when they
click on the cmdAudit button they want Form2 to open on tab Page3 and so on.
Do you think that is possible?
thanks
 

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

Similar Threads


Top