Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GoToRecord after Requery

Posted on 2003-10-26
9
Medium Priority
?
753 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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 375 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

926 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