Solved take Me.PANumberHelp and insert on another form that has focus (1 Viewer)

LeeHutchins

New member
Local time
Today, 08:00
Joined
Nov 3, 2020
Messages
13
I have a form that helps users get a PA number from using a dlookup search, i would then like it to automatically enter itself onto another field that has focus on a different form when they click accept PA number (close)

I would need it to be in the field that has focus as this help form will be used across 4 fields on 2 different forms.

Is this even possible?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:00
Joined
Oct 29, 2018
Messages
21,455
Should be possible. Or, check out if you could use TempVars instead.
 

LeeHutchins

New member
Local time
Today, 08:00
Joined
Nov 3, 2020
Messages
13
Should be possible. Or, check out if you could use TempVars instead.
So i have just clicked about TempVars as i use that for login and user access levels just before i checked here for any more help.

The bit I am stuck on most is how do i get the form to know what field is in focus on my other form as i close the PA Help form? as usually i would just put in the code Me.PANumber = [TempVars]![TempPANo]?

thanks for the quick reply as usual
 

LeeHutchins

New member
Local time
Today, 08:00
Joined
Nov 3, 2020
Messages
13
on form close i have used the below code, it appears to work, though hope that it isnt bad code?

Code:
Dim TempPANo As TempVars
   TempVars!TempPANo = Me.PANumberHelp.Value

DoCmd.Close acForm, "PA Help"

Screen.ActiveControl = ([TempVars]![TempPANo])
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:00
Joined
Oct 29, 2018
Messages
21,455
So i have just clicked about TempVars as i use that for login and user access levels just before i checked here for any more help.

The bit I am stuck on most is how do i get the form to know what field is in focus on my other form as i close the PA Help form? as usually i would just put in the code Me.PANumber = [TempVars]![TempPANo]?

thanks for the quick reply as usual
Hi. When you're on a form and then open another form, the focus should move to the second form, so knowing what was in focus is a little difficult (maybe). Since I cannot see your setup, I'll take a guess.

Let's say you have a form and you click on a button to open the input form as a popup, just make sure you open the popup form in Dialog mode, so you can go back to where you left off in the first form.

Hope that helps...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:00
Joined
Oct 29, 2018
Messages
21,455
on form close i have used the below code, it appears to work, though hope that it isnt bad code?

Code:
Dim TempPANo As TempVars
   TempVars!TempPANo = Me.PANumberHelp.Value

DoCmd.Close acForm, "PA Help"

Screen.ActiveControl = ([TempVars]![TempPANo])
I suppose that would work if the focus automatically goes back to the previous one. I can't guarantee that. Cheers!
 

LeeHutchins

New member
Local time
Today, 08:00
Joined
Nov 3, 2020
Messages
13
Hi. When you're on a form and then open another form, the focus should move to the second form, so knowing what was in focus is a little difficult (maybe). Since I cannot see your setup, I'll take a guess.

Let's say you have a form and you click on a button to open the input form as a popup, just make sure you open the popup form in Dialog mode, so you can go back to where you left off in the first form.

Hope that helps...
I am glad I asked as I didn't even consider the fact that the focus might get changed by the user, and have changed to dialogue mode!

I suppose that would work if the focus automatically goes back to the previous one. I can't guarantee that. Cheers!
seems to be working fine, had a good shot at trying to make it not work, but it appears sturdy enough


as always, thanks for your help :D
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:00
Joined
Oct 29, 2018
Messages
21,455
I am glad I asked as I didn't even consider the fact that the focus might get changed by the user, and have changed to dialogue mode!


seems to be working fine, had a good shot at trying to make it not work, but it appears sturdy enough


as always, thanks for your help :D
Hi. No worries. Good luck with your project.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 17:00
Joined
Jan 20, 2009
Messages
12,851
The active control on any form is available from anywhere in the project as:
Code:
Forms.formname.ActiveControl
Unlike Screen.ActiveControl which only tell you the control currently with the focus, the ActiveControl property of each form persists even when you move the focus to another form.

If you simply move the focus to another already open form by clicking on it then you can just refer directly to this Property of a specific form.

Of course if you have a button on that form to open the other form then that will become the ActiveControl so won't work. In this case, add a custom Public Property to the form and send the control value to it with the LostFocus Event of the controls you need to access from the other form. Whatever was the last control with the focus will always be stored in the Property.

Alternatively you can store the control object itself in the custom Property and read its value. This will allow you to know not just the value in the control but also anything else you might want to know about it.

There is no good reason at all to use a Tempvar in this situation. (theDBguy is overly enamoured with TempVars and suggests them far too often.)
 

Users who are viewing this thread

Top Bottom