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!

Requery and Bookmark do not relocate me to current record

Status
Not open for further replies.

Natha2

Programmer
Dec 23, 2004
17
0
0
BE
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:

Code:
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
 
Hi Natha2!

The following is from the Help screen within access:
Requerying a form invalidates any bookmarks set on records in the form. However, clicking Refresh on the Records menu doesn't affect bookmarks.

Does this help?

Lamar
 
Have a look at:
Access 2003 Bookmark ??
thread705-1306335
 
How are ya Natha2 . . .

Try this (uses the [blue]primarykey[/blue] of the forms recordset):
Code:
[blue]   Dim hldID
   
   hldID = Me![purple][b]PrimaryKeyName[/b][/purple]
   Me.Requery
   Me.Recordset.FindFirst "[[purple][b]PrimaryKeyName[/b][/purple]] = [red][b]'[/b][/red]" & hldID & "[red][b]'[/b][/red]"[/blue]
If the primary key is numeric remove the two single quotes [red]'[/red] in [red]red[/red].

Calvin.gif
See Ya! . . . . . .
 
Hi TheAceMan1,

I tried your solution and got same result as I described.

It appears that when bookmarking, it takes a time to the form to load the data completely. Very strange.

So what I am doing is looping around until form is completely loaded. (it takes less than half a second)

After much changings and re-changing, I came up with following code that works:

Code:
Dim varBkm As adodb.Recordset
Dim a As Integer
Dim RecCountTot As Integer
Dim RecCount As Integer

Set varBkm = Me.RecordsetClone
a = Me.CUST_ID
RecCountTot = varBkm.RecordCount

Me.Requery
SubformAll.Requery

varBkm.Find "CUST_ID=" & a
RecCount = Me.RecordsetClone.RecordCount

          If Not varBkm.EOF Then
            Do
              Me.Bookmark = varBkm.Bookmark
              If RecCountTot <= RecCount Then Exit Do
              RecCount = Me.RecordsetClone.RecordCount
              DoEvents
            Loop
          End If
End Sub

Please feel free to comment.

Thanx to all of you!
 
And what about this ?
Dim a As Integer
a = Me!CUST_ID
Me.Requery
SubformAll.Requery
DoEvents
Me.Recordset.Find "CUST_ID=" & a

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

No success with your code either...
 
. . . and this:
Code:
[blue]   Dim rst As DAO.Recordset, hldID
   
   hldID = Me!CUST_ID
   Me.Requery
   
   Set rst = Me.reordsetclone
   rst.MoveLast
   DoEvents
   Me.Recordset.FindFirst "[CUST_ID] = " & hldID[/blue]

Calvin.gif
See Ya! . . . . . .
 
TheAce, I'm not sure that DAO is well suited for an adp.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
TheAceMan1,

"Me.RecordsetClone" is not supported by DAO.
 
Howdy PHV! . . .

Now that you mention I believe your right. Thanks for the heads up . . .

[blue]Natha2[/blue] remove the [blue]DAO.[/blue] from the rst declaration . . .

Calvin.gif
See Ya! . . . . . .
 
TheAceMan1,

"Me.Recordset" doesn't support the method "FindFirst".

It returns run-time error '438'.

Anyway, FindFirst will maybe find the right record in Me.Recordset, but it will not position the form to that record. In order to do that you must use Bookmark.

The only problem remaining is the "slow" loading of the form, which I eliminate by looping till Me.RecordsetClone.RecordCount (actual number of records presently contained in my form's recordset after requerying) equals MyBookmark.RecordCount (number of records in RecordsetClone before requerying).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top