Solved

GoToRecord after Requery

Posted on 2003-10-26
9
740 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
 

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

932 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

12 Experts available now in Live!

Get 1:1 Help Now