Link to home
Start Free TrialLog in
Avatar of livvie
livvie

asked on

Open pop up form but return focus to same record

I open a pop up form to issue an item from my main form but as soon as I close the popup the cursor goes back to the first record on my main form. I need to be able to stay on the record I was issuing from.
I am using Access 2003 .adp
Any help please.
ASKER CERTIFIED SOLUTION
Avatar of dannywareham
dannywareham
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of livvie
livvie

ASKER

Danny
Where do I declare the public variable (sorry for such a basic question)
In a new module.
Save it.

this allows the variable to be used anywhere in your database - so you can pass the value from the main form to your popup and back.

:-)
BTW. This assumes that you have a unique record identifier (autonumber?) called "RecID"

If it's different, let me know and I'll tailor the code for you...

:-)
Avatar of livvie

ASKER

I am not using a recordset here just the record source of the form. I was trying to avoid using a recordset.
That's fine...
Create the variable.
Capture the value and open the popup:

myRecord = Me.Textboxname    'where textbox name is where the record ID is stored
DoCmd.openForm "YourPopUpForm"


Then use something like (to close teh form and fetch the record you were on before):
DoCmd.Close acForm, "MyPopUpForm", acSaveYes
[forms]![mainformname]![ControlName].Setfocus
Recordset.FindFirst "[RecID]= " & myRecord

Avatar of livvie

ASKER

This line causes a  problem
Recordset.FindFirst "[RecID]= " & myRecord
as the object does not exist I need to be able to refer to the form recourdsource here.
Change to this:

Me.Recordset.FindFirst "RecID=" & myRecord

Also, this assumes that "RecID" is the name of the unique field in your table
If it is different, change it...

:-)
Avatar of livvie

ASKER

This Recordset.FindFirst "[StoresID]= " & myRecord needs to be somewhere on the mainform I am assuming seeing as that is the recordset  I am lookng for the record in. I have put in numerous places like the gotfocus event of the text box that I have setfocus on in the save event of my pop up but I never seem to go into this code. I have also tried the form gotfocus event.
Avatar of Hamed Nasr
Couldn't reproduce the effect.
Avatar of livvie

ASKER

OK I have a solution to the problem. (don't requery the main form) but I need to requery one field so maybe if anyone has an alternative to requerying the form instead.
Avatar of livvie

ASKER

I have it. I am requerying the container form of the form I am working on.
dannywareham thanks for you help.
I will give you the points as your solution would work if I wanted to do it that way.