473,417 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

Bookmark datatype mismatch error

I need to make sure that I am on a different record than I just was
on, in a DAO recordset.

code fragment:

1. strFind = "thisSource = " & tripID & " AND thisTrip = " & tripID
2. rs.FindFirst (strFind)
3. If Not rs.NoMatch Then
4. strBookmark = rs.Bookmark
5. rs.MoveFirst
6. If rs.Bookmark = strBookmark Then rs.MoveNext
7. ...and so on

it wont compile because of a type mismatch, highlighting the equal
sign on line 6; not on line 4.

I have cast my bookmark variable as string, long, variant, with the
same result. I can probably do this another way, but I want to know
why it isn't working this way, first. -tc

Apr 23 '07 #1
11 4243
From memory, bookmarks are case-sensitive variants.

Try declaring:
Dim varBookmark As Variant

Then at line 4:
varBookmark = rs.Bookmark

Then at line 6:
If StrComp(rs.Bookmark, varBookmark, vbBinaryCompare) = 0 ...

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Tom Clavel" <to*******@ouraynet.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
>I need to make sure that I am on a different record than I just was
on, in a DAO recordset.

code fragment:

1. strFind = "thisSource = " & tripID & " AND thisTrip = " & tripID
2. rs.FindFirst (strFind)
3. If Not rs.NoMatch Then
4. strBookmark = rs.Bookmark
5. rs.MoveFirst
6. If rs.Bookmark = strBookmark Then rs.MoveNext
7. ...and so on

it wont compile because of a type mismatch, highlighting the equal
sign on line 6; not on line 4.

I have cast my bookmark variable as string, long, variant, with the
same result. I can probably do this another way, but I want to know
why it isn't working this way, first. -tc
Apr 23 '07 #2
Thanks. It works just right. -tc

On Apr 22, 10:07 pm, "Allen Browne" <AllenBro...@SeeSig.Invalid>
wrote:
From memory, bookmarks are case-sensitive variants.

Try declaring:
Dim varBookmark As Variant

Then at line 4:
varBookmark = rs.Bookmark

Then at line 6:
If StrComp(rs.Bookmark, varBookmark, vbBinaryCompare) = 0 ...

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Tom Clavel" <tomcla...@ouraynet.comwrote in message

news:11**********************@e65g2000hsc.googlegr oups.com...
I need to make sure that I am on a different record than I just was
on, in a DAO recordset.
code fragment:
1. strFind = "thisSource = " & tripID & " AND thisTrip = " & tripID
2. rs.FindFirst (strFind)
3. If Not rs.NoMatch Then
4. strBookmark = rs.Bookmark
5. rs.MoveFirst
6. If rs.Bookmark = strBookmark Then rs.MoveNext
7. ...and so on
it wont compile because of a type mismatch, highlighting the equal
sign on line 6; not on line 4.
I have cast my bookmark variable as string, long, variant, with the
same result. I can probably do this another way, but I want to know
why it isn't working this way, first. -tc

Apr 23 '07 #3
Tom Clavel <to*******@ouraynet.comwrote in
news:11**********************@e65g2000hsc.googlegr oups.com:
I need to make sure that I am on a different record than I just
was on, in a DAO recordset.

code fragment:

1. strFind = "thisSource = " & tripID & " AND thisTrip = " &
tripID 2. rs.FindFirst (strFind)
3. If Not rs.NoMatch Then
4. strBookmark = rs.Bookmark
5. rs.MoveFirst
6. If rs.Bookmark = strBookmark Then rs.MoveNext
7. ...and so on

it wont compile because of a type mismatch, highlighting the equal
sign on line 6; not on line 4.

I have cast my bookmark variable as string, long, variant, with
the same result. I can probably do this another way, but I want
to know why it isn't working this way, first.
Why are you storing the bookmark? Are you going to keep track of
more than one bookmark at a time?

Wouldn't what you are doing make much more sense testing real values
in the records, instead of the bookmarks?

I have never once stored a bookmark in a variable, so don't quite
see the point. It's data that is much too volatile to be stored,
seems to me.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Apr 23 '07 #4
On Apr 23, 10:16 am, "David W. Fenton" <XXXuse...@dfenton.com.invalid>
wrote:
Tom Clavel <tomcla...@ouraynet.comwrote innews:11**********************@e65g2000hsc.google groups.com:


I need to make sure that I am on a different record than I just
was on, in a DAO recordset.
code fragment:
1. strFind = "thisSource = " & tripID & " AND thisTrip = " &
tripID 2. rs.FindFirst (strFind)
3. If Not rs.NoMatch Then
4. strBookmark = rs.Bookmark
5. rs.MoveFirst
6. If rs.Bookmark = strBookmark Then rs.MoveNext
7. ...and so on
it wont compile because of a type mismatch, highlighting the equal
sign on line 6; not on line 4.
I have cast my bookmark variable as string, long, variant, with
the same result. I can probably do this another way, but I want
to know why it isn't working this way, first.

Why are you storing the bookmark? Are you going to keep track of
more than one bookmark at a time?

Wouldn't what you are doing make much more sense testing real values
in the records, instead of the bookmarks?

I have never once stored a bookmark in a variable, so don't quite
see the point. It's data that is much too volatile to be stored,
seems to me.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/- Hide quoted text -

- Show quoted text -
Bookmarks are strings in case anyone wants to know. I've used them a
lot to mark records or to position to a specific record in a form. If
I remember correctly (always an issue!), one of the form wizards uses
bookmarks in the generated code.
-- Larry Engles
Access developer since day 1 of Access 1.0

Apr 24 '07 #5
<en****@ridesoft.comreplied in message
news:11*********************@o40g2000prh.googlegro ups.com...
Bookmarks are strings in case anyone wants to know.
Larry, that's not strictly correct. Bookmarks are a variant array of bytes.

You can make them display like strings, but attempting to use them as
strings can fail. That's exactly what the original poster in this thread
discovered.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

Apr 24 '07 #6
On Apr 23, 9:54 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
<eng...@ridesoft.comreplied in messagenews:11*********************@o40g2000prh.go oglegroups.com...
Bookmarks are strings in case anyone wants to know.

Larry, that's not strictly correct. Bookmarks are a variant array of bytes.

You can make them display like strings, but attempting to use them as
strings can fail. That's exactly what the original poster in this thread
discovered.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
I did not know that. I've always declared them as strings and have
never had a problem. I see (now) that help shows them being used as
variants. If I recall, I experimented (we're talking Access 1.1 or
2.0 probably) to find how to declare them.

It's not clear to me how an "array of bytes" differs from a string.
Is it a zero terminator?

Thanks,

-- Larry Engles
Access developer since day 1 of Access 1.0

Apr 24 '07 #7
It is possible to visualize a string as an array of bytes. Some languages
(e.g. Pascal) do that.

However, strings may not be bytes, e.g. Unicode. And strings in some
languagues are null terminted, so the first chr(0) in the string would be
interpreted as the end of the string.

In VBA, strings are not arrays:
? IsArray("Hello")
whereas bookmarks are:
? IsArray(Forms(0).Bookmark))
(assuming the first form is open, bound, and not at a new record.)

Treating a bookmark as as string wrongly reports it as 2 characters long:
? Len(Forms(0).Bookmark) 'WRONG!

In fact, it is an array of 4 bytes:

Sub ExamineBM()
Dim varBM As Variant
Dim i As Long
Dim bt As Byte
varBM = Forms(0).Bookmark
For i = LBound(varBM) To UBound(varBM)
bt = varBM(i)
Debug.Print bt
Next
End Sub

A bookmark is therefore more like IP address than a string.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<en****@ridesoft.comwrote in message
news:11**********************@r30g2000prh.googlegr oups.com...
On Apr 23, 9:54 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
><eng...@ridesoft.comreplied in
messagenews:11*********************@o40g2000prh.g ooglegroups.com...
Bookmarks are strings in case anyone wants to know.

Larry, that's not strictly correct. Bookmarks are a variant array of
bytes.

You can make them display like strings, but attempting to use them as
strings can fail. That's exactly what the original poster in this thread
discovered.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

I did not know that. I've always declared them as strings and have
never had a problem. I see (now) that help shows them being used as
variants. If I recall, I experimented (we're talking Access 1.1 or
2.0 probably) to find how to declare them.

It's not clear to me how an "array of bytes" differs from a string.
Is it a zero terminator?

Thanks,

-- Larry Engles
Access developer since day 1 of Access 1.0
Apr 24 '07 #8
en****@ridesoft.com wrote in
news:11*********************@o40g2000prh.googlegro ups.com:
If
I remember correctly (always an issue!), one of the form wizards
uses bookmarks in the generated code.
It uses them but does not store them. I use them just the way the
wizard does, for bookmark navigation, but I would never store a
bookmark value.

I can't come up with a reason for doing so.

If I want to navigate to a particular record after departing it to
go to another, I store the PK of the record and navigate to that.
That insures that a requery in between won't invalidate the value
I'm storing.

Can anyone come up with a scenario where storing a bookmark value is
the only way to accomplish the task?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Apr 24 '07 #9
David, I almost never store a bookmark in a variable either, but I have used
this occassionally:

Dim varBM As Variant
varBM = rs.Bookmark
'move the recordset somewhere else, e.g. to read a value
rs.Bookmark = varBM

Using a bookmark to return to the record is (reportedly) the most efficient
approach - certainly faster than FindFirst.

And Access does store maintain some bookmarks in memory too, such as
LastModified.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"David W. Fenton" <XX*******@dfenton.com.invalidwrote in message
news:Xn**********************************@127.0.0. 1...
en****@ridesoft.com wrote in
news:11*********************@o40g2000prh.googlegro ups.com:
>If
I remember correctly (always an issue!), one of the form wizards
uses bookmarks in the generated code.

It uses them but does not store them. I use them just the way the
wizard does, for bookmark navigation, but I would never store a
bookmark value.

I can't come up with a reason for doing so.

If I want to navigate to a particular record after departing it to
go to another, I store the PK of the record and navigate to that.
That insures that a requery in between won't invalidate the value
I'm storing.

Can anyone come up with a scenario where storing a bookmark value is
the only way to accomplish the task?
Apr 25 '07 #10
On Apr 23, 9:54 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
<eng...@ridesoft.comreplied in messagenews:11*********************@o40g2000prh.go oglegroups.com...
Bookmarks are strings in case anyone wants to know.

Larry, that's not strictly correct. Bookmarks are a variant array of bytes.

You can make them display like strings, but attempting to use them as
strings can fail. That's exactly what the original poster in this thread
discovered.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
Maybe the 3rd time trying to reply will work!

That bookmarks are variants was a surprise to me - after 10+ years of
using them as strings! Coulda looked in help I guess, but who needs
help when it works? I will confess that I've never compared two
bookmarks tho.

Anyway, thanks for the heads-up. By the way, what is the difference
between a string and a variant array of bytes? I don't recall if
strings in VBA are zero terminated or not. Is that perhaps the
difference?
-- Larry Engles
Access developer since day 1 of Access 1.0

Apr 25 '07 #11
"Allen Browne" <Al*********@SeeSig.Invalidwrote in
news:46***********************@per-qv1-newsreader-01.iinet.net.au:
David, I almost never store a bookmark in a variable either, but I
have used this occassionally:

Dim varBM As Variant
varBM = rs.Bookmark
'move the recordset somewhere else, e.g. to read a value
rs.Bookmark = varBM

Using a bookmark to return to the record is (reportedly) the most
efficient approach - certainly faster than FindFirst.
Well, I guess if you're jumping around a recordset hundreds of times
to do something, that might very well be so. But if you're doing it
but once I don't see any value to shaving off a couple of
milliseconds.

For what it's worth, I optimized a FindFirst in a large recordset
ordered on the value used in the FindFirst by choosing
FindNext/FindPrevious. Because the order of the records I was
processing didn't matter (I was doing some calculatations, the order
of which didn't matter), I could do them either top-to-bottom or
bottom-to-top. I found that it really did improve response time, and
the improvement was linearly proportional to the distance of the
sought value from the beginning of the recordset. This caused me to
conclude that FindFirst *always* starts from the beginning of the
recordset, rather than properly using the index to shortcut that.
And Access does store maintain some bookmarks in memory too, such
as LastModified.
But you don't know how volatile that pointer is if you store it.
That is, Access takes care of keeping LastModified up-to-date, but
if you store the value, you've got to keep track of it yourself.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Apr 25 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephen Briley | last post by:
For some reason, my posts are scrubbed as attachments. Lets hope that sending from the yahoo account works. I'm new to Python and I'm trying to do some database work with MS Access, but I can't...
2
by: Steve Briley | last post by:
I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error".&nbsp; Here's an example table that I'm working with... ...
1
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. ...
2
by: JingleBEV | last post by:
Hi, Iam coding data access application with database object and recordset. Here' s my code '------------------------------------------------------------------ Private Function CreateRecordSet()...
6
by: rn5a | last post by:
I am inserting records in a MS-Access database table. The data type of one of the columns named *OrderDate* in the DB table is Date/Time. This is the SQL query I am using to insert the records in...
2
by: chirag1989 | last post by:
I m havin an error of datatype mismatch actual here i m askin user to input the code in text box and then searchin the record havin that code in database the problem is the code field Bnum is of...
0
by: Snoopy33 | last post by:
I have a query that builds a date from a text field with the date imput as yyyymmdd in the query, so i have to piece it together in my expression as follows: exp:...
9
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done...
14
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.