Going 1st record...urgent help

S

sencan777

Dear sir,

I have a form and a button on it. When I press that button, OnClic
event runs.
and "Me.Requery" code runs.
I changes the results but it goes to first record of form.
How will I fix the current record on the screen
 
N

Nikos Yannacopoulos

On Error Resume Next
vCurrent = Me.Bookmark
Me.Requery
Me.Bookmark = Me.Current

HTH,
Nikos
 
S

sencan777

On Error Resume Next
vCurrent = Me.Bookmark
Me.Requery
Me.Bookmark = Me.Current

when I run this codes I get compile error on "Vcurrent"
what is problem
 
N

Nikos Yannacopoulos

Oops! Wrong again! My brain must be on strike today. This is what the
code should be:

Dim vCurrent
On Error Resume Next
vCurrent = Me.Bookmark
Me.Requery
Me.Bookmark = vCurrent

Sorry for the confusion...
 
S

sencan777

wow..great..without "Me", vCurrent works...no compile error..
butttt...problem is same...that is when I press the button (onclick
and run this code,
I go to the first record of form...I can not stand at current record..
any idea
 
N

Nikos Yannacopoulos

Don't know why. It works for me.

You might want to try a different approach that someone else suggested
in another thread recently:

Dim rst As DAO.Recordset
Dim lngID As Long
lngID = Me.[Tel ID] 'the control
Me.Requery
Set rst = Me.RecordsetClone
rst.FindFirst "[Tel ID] = " & lngID 'the field name
If Not rst.NoMatch Then
Me.Bookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing

This utilizes the record's PK field value; as far as I can tell, the
table field is named [Tel ID], and the control on the form bound to it
has the same name. The above syntax is for numeric PK field.

HTH,
Nikos
 
A

Albert D.Kallal

Me.Requery
Me.Bookmark = vCurrent

If you requlery a reocrdset, or a form, then all bookmarks are not valid. I
am not sure why the above works for you, but you can't use, nor rely on any
bookmarks when a requery is done.
 
N

Nikos Yannacopoulos

If you requlery a reocrdset, or a form, then all bookmarks are not valid. I
am not sure why the above works for you, but you can't use, nor rely on any
bookmarks when a requery is done.
There should be a catch... it works for me most likely because I haven't
used it extensively, and I've been lucky so far, I suppose. I realize
the recordset is (most likely) no longer the same after a requery, but I
had intuitively expected the bookmark to evaluate to the same array for
a given record, if that record still exists in the new recordset. I'm
probably wrong, but I guess I would need to know how the bookmark value
(array) is determined, in order to answer this. Would you happen to know
this technicality?

Thanks,
Nikos
 
A

Albert D.Kallal

I guess I would need to know how the bookmark value (array) is determined,
in order to answer this. Would you happen to know this technicality?

Hum, no, I don't exactly.

I believe it is a hash-code string based on a internal number that resolves
to the memory pointer in the recordset, not on disk. The fact that you can
use bookmarks without a primary key in a record tells me that there is some
type of other identifier made here. If it is not a hash code, then likely it
is a off set in bytes into the recordset array.

The above means that if you create two reocrdsets based on the SAME query,
the bookmarks again can NOT be used interchangeably.

If you use the clone method of a recordset, then YOU CAN use book marks
between both reocrdsets, since they are based on the SAME memory variable
from the start..

Regardless, any requery of a recordset means you can't use bookmarks, and
they are NOT valid anymore.
 
N

Nikos Yannacopoulos

Albert,

I did a small experiment on a ~790 record recordset; I printed the
bookmark's 4 bytes for each record, and noticed that they were
sequential (hex) up to a point, then there was a gap, then another
sequential block etc. I also played with inserting a record at a certain
place and looking at how that affected the bookmarks of the records
before and after the new one; so, if I inserted a record right before
record X, X-1 remained X-1, the new record became X, and the previously
X became X+1... no surprise here. Not sure what to make out of all
this... I would have thought that possibly the bookmark value is an
offset from a starting memory address, while not all records are
necessarily stored in one continuous block (presumably, memory being
managed in a way similar to files on a disk, as far as fragmentation
goes), but the fact the bookmark increment within continuous blocks is
1, doesn't seem to support this theory.

So, I'm still left with the question, but at least I'm wiser now as to
when not to rely on bookmarks! Anyway, thanks for taking the time.

Regards,
Nikos
 
A

Albert D.Kallal

I did a small experiment on a ~790 record recordset; I printed the
bookmark's 4 bytes for each record, and noticed that they were
sequential (hex) up to a point, then there was a gap, then another
sequential block etc.

Very interesting. My bests are that you are seeing some reference into a
BLOCK of disk (or memory space).

Remember, ms-access uses 2000 byte blocks, and stuffs in as many records it
can into that block (with some room left over).

So, you might be seeing is that when the block is full, one moves on to the
next block of memory. While I have not really studied the internal workings
of the jet database, I most certainly have studied the workings of database
engines, and JET is very much like other systems in that is uses blocks of
disk space, and stuffs records into those blocks. Remember, each record in
ms-access is a variable length record, so what happens is the data engine
resolves the record to some block of data on disk. At this point a
sequential scan occurs to pull out the record from that block. Often, if you
add just FEW bytes of data into a record, and then write it back to disk,
the new record now can't fit into the 2000k block, so some records are
pushed (split out) into a NEW 2000k block (this explains why a file bloats
SO quickly right after a compact and repair - what happens is all records
are packed tightly as possible into 2000k blocks. However, when records are
expanded a bit, then new 2000k blocks are often created since they expands
out of the 2000k block. When a good number of these new blocks have been
created, then file expansion is becomes VERY low when you update, or edit
data.
 
Top