Solved

GoToRecord after Requery

Posted on 2003-10-26
9
742 Views
Last Modified: 2012-06-27
Hi Experts,

I've got a form that with a subdatasheet that gets requeried on the close event of a form that gets opened from the subdatasheet. As you know, the requery caused the current record to go back to record 1. To keep the current record the same as the current record before the requery, I've tried to record the record number and use GoToRecord to return.

I'm getting the error: "The object 'Forms![frmFilteredUnitSchedule].[subUnitSchedule]' isn't open." Does anyone have any ideas about how I can restore the current record?

Code:
Private Sub Form_Close()

    Dim lngRecordNumber As Long
    Dim strForm As String
   
    intRecordNumber = Forms![frmFilteredUnitSchedule].[subUnitSchedule].[Form].CurrentRecord
    strForm = "Forms![frmFilteredUnitSchedule].[frmUnitSchedule]"
   
    Forms![frmFilteredUnitSchedule].[subUnitSchedule].[Form].Requery

    DoCmd.GoToRecord acDataForm, strForm, acGoTo, intRecordNumber
   
End Sub

Regards,
troycox
0
Comment
Question by:troycox
  • 5
  • 4
9 Comments
 
LVL 26

Expert Comment

by:Alan Warren
ID: 9624409
Hi Troy,

What is the code that you are using to open the form that gets opened from the subdatasheet?

Does this form add records that the calling form needs to include in it's recordset?

Alan
0
 

Author Comment

by:troycox
ID: 9624422
I open the form with:

    Dim strForm As String
    Dim strWhereCondition As String
   
    strForm = "subPurchaserDetail"
    strWhereCondition = "[Client ID]=[Forms]![frmFilteredUnitSchedule]![subUnitSchedule].[Form]![txtClientID]"
   
    DoCmd.OpenForm strForm, acNormal, , strWhereCondition, acFormPropertySettings, acWindowNormal

It's not possible to add records, but data in the existing records gets changed which reflects data in the subdatasheet and hence the requirement for the requery on the subdatasheet.

Regards,
troycox
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 9624481
Hi Troy,

If you open the form dialog mode the code that you use to open the form will wait until you have finished editing the record before executing the next line.

Dim strForm As String
    Dim strWhereCondition As String
   
    strForm = "subPurchaserDetail"
    strWhereCondition = "[Client ID]=[Forms]![frmFilteredUnitSchedule]![subUnitSchedule].[Form]![txtClientID]"
   
' Code waits for this to close
DoCmd.OpenForm( strForm, acNormal, , strWhereCondition, acFormPropertySettings, acDialog

'
Dim lngRecordNumber As Long
lngRecordNumber = Me.CurrentRecord
Me.requery    'or me.Refresh
DoCmd.GoToRecord acDataForm, strForm, acGoTo, lngRecordNumber


Alan

p.s. You seem to be dimensioning lngRecordNumber as a long integer but referring to it as intRecordNumber

Option Explicit at the top of your Form Code module will fix this.
But it may also raise other compile problems.







0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:troycox
ID: 9624598
Thanks Alan,

A bit closer. I still get the error, "Object: 'subUnitSchedule' is not open."

I'm using this code to open of frmPurchaserDetail:

    Dim strForm As String
    Dim strWhereCondition As String
    Dim lngRecordNumber As Long
   
    strForm = "subPurchaserDetail"
    strWhereCondition = "[Client ID]=[Forms]![frmFilteredUnitSchedule]![subUnitSchedule].[Form]![txtClientID]"
    lngRecordNumber = Me.CurrentRecord
   
    ' Code waits for this to close
    DoCmd.OpenForm strForm, acNormal, , strWhereCondition, acFormPropertySettings, acDialog

    ' After the opened form closes, this code executes
    Me.Refresh
    DoCmd.GoToRecord acDataForm, "subUnitSchedule", acGoTo, lngRecordNumber

I've tried using the fully qualified form name ([Forms]![frmFilteredUnitSchedule]![subUnitSchedule]) and the basic form name (subUnitSchedule) and neither seem to work.
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 9624624


strWhereCondition = "[Client ID]=" & Form_frmFilteredUnitSchedule!subUnitSchedule.Form.txtClientID
0
 

Author Comment

by:troycox
ID: 9624653
Hi Alan,

Sorry, it's not the OpenForm command that is failing, it is the GoToRecord command that is failing.

DoCmd.GoToRecord acDataForm, "subUnitSchedule", acGoTo, lngRecordNumber

It doesn't like "subUnitShedule" which is a subform of "frmFilteredUnitSchedule".

Regards,
troycox
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 125 total points
ID: 9624734
Hi Troy,

Have you investigated the use of bookmarks, for record navigation?


In a form, I want to  bookmark a record, requery the form, then return to the bookmarked record.
http://www.experts-exchange.com/Databases/MS_Access/Q_10334897.html

Alan
0
 

Author Comment

by:troycox
ID: 9630893
Got it to work. I used bookmarks as per Alan's suggestion in:
http://www.experts-exchange.com/Databases/MS_Access/Q_10334897.html

Here's my code:

    Dim strForm As String
    Dim strWhereCondition As String
    Dim lngRecordNumber As Long
   
    strForm = "subPurchaserDetail"
    strWhereCondition = "[Client ID]=" & Form_frmFilteredUnitSchedule!subUnitSchedule.Form.txtClientID
    lngRecordNumber = Me.CurrentRecord
   
    ' Code waits for this to close
    DoCmd.OpenForm strForm, acNormal, , strWhereCondition, acFormPropertySettings, acDialog

    ' After the opened form closes, this code executes
    Dim f As Form
    Dim lngSaveID As Long
   
    Set f = [Forms]![frmFilteredUnitSchedule]![subUnitSchedule].[Form]
    lngSaveID = f![Property ID]  ' My keyID
    f.Refresh
   
    Dim r As Recordset
    Set r = f.RecordsetClone
   
    r.FindFirst "[Property ID] =" & lngSaveID
    f.Bookmark = r.Bookmark

Regards,
troycox
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 9630996
Good one troycox!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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