Solved

GoToRecord after Requery

Posted on 2003-10-26
9
739 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

708 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

13 Experts available now in Live!

Get 1:1 Help Now