Solved

VBA: Select Next Record on Subform After Refresh

Posted on 2014-11-07
5
526 Views
Last Modified: 2014-11-08
I have an MS Access application that uses a dialog box with various selection criteria to run a report.  Once the report has run, I update a timestamp that displays on an underlying subform.

What I'd like to do, is to run the report, and on closing the report, refresh the subform (contained within a separate form beneath the dialog box), and select the next record in the subform.

Summary:

 1. Run report from dialog box with selection criteria.
 2. On report close, refresh the subform within the underlying form.
 3. Select the next record that follows the one previously run.

Hopefully, this makes some kind of sense.  I think this SHOULD be relatively easy, but I'm getting stuck on syntax.

Please let me know what else I can provide.
SubformRecordSelect.png
0
Comment
Question by:Donovan Moore
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40429890
re:>  refresh the subform within the underlying form.

Why you need to refresh? Has its date changed?

When you close the report, the focus returns to the form and OnActive event of the form fires.

I will give you more detailed info later. In a public variable, you will store the PK of the record you want the form to show e=when the report is closed. Then in OnActive event, you can use bookmark to move to the record with PK you have stored in the public variable we talked about.

Mike
0
 

Author Comment

by:Donovan Moore
ID: 40429892
Sorry for not explaining - running the report sets the generated date.  I want to refresh the subform to show the new date.
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40429895
Public lngPK as Long
for now put this in a module outside the form, later on we may be able to bring inside the form in question.


In on Active event of the main form (not subform) have:

Me!SubromName,FormRefreshSubform

In subform after decorations have

Public Sub  FormRefreshSubform()
  MsgBox "FormRefreshSubform fires ok"
End Sub

Apply these until first you get "FormRefreshSubform fires ok" message. We will continue.

Mike
0
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40429899
Q1: Can you store the next recod PK in lngPK variable? if not sure then:

Q2:What is the field name for PK in the subform?
Q3: What field the subform sorted by?
-------------
replace the MsgBox "..." with the following lines:

Public Sub  FormRefreshSubform()
  'MsgBox "FormRefreshSubform fires ok"
  Me.Requery
  Me.Recordset.FindFirst "ID=" & lngPK
End Sub

Change ID to whatever you have on the subform.
0
 

Author Closing Comment

by:Donovan Moore
ID: 40430711
I got it working...differently than what was suggested, but you certainly got me pointed in the right direction.  Thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now