confused about GUIDs

R

Roland Alden

I've observed that guids (uniqueidentifiers) appear to have "second class"
status in Access. However, something I ran across just now really has me
puzzled.

I know that most controls bound to a guid have a value which is an array of
0..15 bytes. When displayed as text these values appears between braces {}
as a string of guid-stuff like {xxx...xxx}.

However in many API's there is a need to pass the guid value as part of an
sql or sql-like syntax. For these situations I have been using
StringFromGUID which returns a string that has an extra layer of syntactic
sugar: {guid{xxx...xxx}}. When string concating up a where clause, for
example, I've resorted to ugly sequences of code like this:

q = StringFromGUID(Me.uid)
q = Replace(q, "{guid {", "{")
q = Replace(q, "}}", "}")
q = "uid=" & q

which will turn {guid{xxx...xxx}} returned by StringFromGUID into
uid={xxx...xxx} which can be used as a sql where for example. This has
worked just fine up until this morning when I was passing it to

DoCmd.OpenForm stDocName, acNormal, , q, acFormEdit, acDialog

And found that OpenForm did not return an error, but did not open either. I
assumed that somehow the GUID was wrong or uid={xxx...xxx} wasn't a valid
where for that particular form, etc. I kept inspecting the string q for
incorrect issues.

I have observed that SQL Server has its own ideas about the syntax for GUIDs
as well. It seems to like '{xxx...xxx}' for a string literal most of the
time. So just for the heck of it I tried replacing the { } delimiters with '
and ' in this case.

I.e., instead of

uid={xxx...xxx}

I passed

uid='xxx...xxx'

to OpenForm.

And it worked! However, in all other places I use {} and have had no trouble
until now. I'm not sure what is special about this case and what the real
rules are?
 
Top