Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Returning to same record
Bill Carver 

2 years ago
For reasons of style I have a form that consists of subforms.  This form's data source is a linked table called "drivers"

On this forms are reports and subforms that are based on queries.  I've added a "choose date range" button to the form with the following script

Private Sub ChooseDateBTN_Click()
  TempVars("selecteddriver") = [Driver ID].Value
  DoCmd.OpenForm "datepicker"
End Sub


As you can see I'm using a tempvar "selecteddriver" to identify the current record in the form that i"m on.   I've also tried getting the current record number as well.   THe datepicker form is a popup form so what I need to happen is that I can choose the form, close it and refresh the form that I'm looking at. (in this case, drivers).  When I open this form and choose dates it works but when it returns to the refresh form it always returns to the first record.

Here's the script on the ok button of the popup form.

DetailsPrivate Sub okbtn_Click()
On Error Resume Next
TempVars("SelectedStartDate") = Nz(StartDate.Value, 0)
TempVars("Selectedenddate") = Nz(EndDate.Value, 0)
DoCmd.Close
Dim f As Form

    For Each f In Access.Forms
        f.Requery
    Next

'On Error GoTo skipit
DoCmd.OpenForm "drivers", acNormal, , driverid = [TempVars]![selectedriver]

DoCmd.Requery

skipit:
DoCmd.OpenForm "drivers"
End Sub


How can I get it to return to the same record after the refresh.
Juan Rivera  @Reply  
            
2 years ago
Try this and see if it helps.
Requery in Place
Bill Carver OP  @Reply  

2 years ago
Thanks Juan.  That worked.  I assume I need to do the same thing to all the subforms on the main form, then the subform?
Juan Rivera  @Reply  
            
2 years ago
you have the lego build it the way you like.... LOL have fun doing it.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/30/2026 3:10:02 AM. PLT: 0s