Solved

Converting DAO Field Property GUID

Posted on 2012-04-08
3
496 Views
Last Modified: 2012-04-08
I am trying to write a procedure that lists the field properties and attributes for the tables in a database.
The procedure loops through all of the DAO Field Properties.
One of the properties is a GUID (at least that's what its name is). If I look at the value of this property in the local window, it is defined as 'variant/byte (0 to 15)'.
image 1I am trying to figure out how to convert this value to a standard GUID format
e.g.:      {361AA560-4FB1-11D3-AAE0-00104BA31425}
In the past, I have used a module (basGUIIDs) for handling GUIDs. The code is listed below. This module defines a public variable type named GUID:

Public Type GUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(7) As Byte
End Type

All of the procedures in the basGUIDs module use this GUID type for input.
I tried to add some code to the procedure to convert the value to a GUID, but I'm running into a problem.  In my procedure, if the property name is 'GUID', I attempt to move the property value into a variable defined as type GUID:

Dim GID As GUID

If .Name = "GUID" Then
      GID = .Value

I am getting a compiler error on the 'GID = .Value' line:

Compiler Error
Only user-defined types defined in public object modules can be
coerced to or from a variant or passed to late bound functions.
image 2I don't really know what this error means and how I should handle it. I have a feeling this particular approach isn't going to work anyway.
My question is how can I convert this array into a 'standard' GUID? Or am I completely off base here?
For the purposes of this question, I have attached a copy of the database. I am working with Access 2010 (32 bit) on a Windows 7 Ultimate (64 bit) platform.
Thanks,
Todd
GIUD-Compile-Error.accdb
0
Comment
Question by:shambalad
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
Comment Utility
I think it is byte presentation of GUID and you can convert it to string with this function:
Function GUID(A As Variant) As String
Dim i As Integer, H As String
GUID = ""
For i = 0 To 15
    If i = 4 Or i = 6 Or i = 8 Or i = 10 Then GUID = GUID & "-"
    H = Hex(A(i))
    If Len(H) < 2 Then H = "0" & H
    GUID = GUID & H
Next
End Function

Open in new window

You can call it from your function:
If .Name = "GUID" Then
                              Debug.Print GUID(.Value)
End If   'If .Name = "GUID"
0
 
LVL 7

Author Comment

by:shambalad
Comment Utility
Hex! That's the function I was looking for.
I have done little with bytes, binaries and hexadecimals in the past. This has been a learning experience for me.
Your function works like a charm.
0
 
LVL 7

Author Closing Comment

by:shambalad
Comment Utility
Thank you for your help.
Todd
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now