Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Requery to return me to current record

Status
Not open for further replies.

Prufrock

Instructor
Sep 4, 2002
77
0
0
AU
I have a form and subform. They are linked by a name field. Once I select the name from a combo box in the main I want the subform to update. I have been getting this to work fine by requerying on exit ( as I tab out of the combo box) except that I go back to first record on requery and then have to click to the last entry.

The requerying forces the name to be fed as the criteria into a query that the subform is based on.

What is the simplest way to get the requery to take me back to the record I am in at the end rather than back to the beginning? The form has a unique number used as the Primary key.

Any help appreciated.
 
If it is a record by position (first, last, next, previous) or record number, you can use DoCmd.GoToRecord. If you wish to find a record by ID, you can use the subform Recordset:

Me.[Subform Control Name].Form.Recordset.FindFirst "ID=" & Name_Of_Saved_ID_Variable_Or_Control

Or there abouts
 
. . . example code:
Code:
[blue]   Dim sfrm As Form
   
   Set sfrm = [[purple][b]subFormName[/b][/purple]].Form
   [green]'
   'Your code
   '[/green]
   sfrm.Requery
   
   If sfrm.Recordset.RecordCount > 1 Then
      [b]DoCmd.RunCommand acCmdRecordsGoToLast[/b]
   End If

   Set sfrm = Nothing
[/blue]
If you post the code your using it'll give us better insight!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
I tried the suggestion of danvlas, without success:

I am having a form in adp (access project with SQL Server as backend).

In order to refresh the form to view data eventualy changed by other users, I have on the form a button with following "on click" event:

Dim varBkm As Variant

varBkm = Me.Bookmark
Me.Requery
Me.Bookmark = varBkm

Data source represents 12682 records, however after clicking, the form's record selector says "Record: 1 of 2251...". (it can be any number, but it is always far below 12682)

It seems that when executing the above code it doesn't reload all the records in the form, resulting in not relocating to the right record.

If I refresh the first 2251 records = no problem.

Refreshing a record bigger than 2251 = relocating on record 2251.

Do you have any other suggestion(s)?

Thanx in advance 'cause I spend already hours in this forum and other ones without result...

Natha
 
How are ya Natha2 . . .

Mixing threads is a bad idea!

Start your own thread, this way you'll have full attention of the forum and others may benefit from your soultion! [thumbsup2]

BTW: Be sure to have a serious look at FAQ219-2884 or FAQ181-2886

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top