• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

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.
0
livvie
Asked:
livvie
  • 6
  • 5
1 Solution
 
dannywarehamCommented:
Create a public variable:

Public myRecord as String


Capture the value of the record (RecID) before opening the popup form.
When you close teh form, use FindFirst to return to teh previous record:

Recordset.FindFirst "[RecID]= " & myRecord
0
 
livvieAuthor Commented:
Danny
Where do I declare the public variable (sorry for such a basic question)
0
 
dannywarehamCommented:
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.

:-)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
dannywarehamCommented:
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...

:-)
0
 
livvieAuthor Commented:
I am not using a recordset here just the record source of the form. I was trying to avoid using a recordset.
0
 
dannywarehamCommented:
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

0
 
livvieAuthor Commented:
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.
0
 
dannywarehamCommented:
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...

:-)
0
 
livvieAuthor Commented:
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.
0
 
hnasrCommented:
Couldn't reproduce the effect.
0
 
livvieAuthor Commented:
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.
0
 
livvieAuthor Commented:
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.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now