Solved

GoToRecord after Requery

Posted on 2003-10-26
9
746 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 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