全部显示

GUIDFromString 函数

   

GUIDFromString 函数将字符串转换为 GUID,其值为 Byte 数据类型的数组

GUIDFromString(stringexpression)

GUIDFromString 函数具有以下参数:

参数 说明
stringexpression 对字符串形式的 GUID 进行计算的字符串表达式

说明

Microsoft Jet 数据库引擎将 GUID 保存为 Byte 类型的数组。但是,Microsoft Access 不能从窗体报表上的控件中返回 Byte 数据。为了从控件中返回 GUID 的值,必须将它转换为字符串。若要将 GUID 转换为字符串,请使用 StringFromGUID 函数。若要将字符串转换为 GUID,请使用 GUIDFromString 函数。

示例

下面的示例使用 GUIDFromString 函数将字符串转换为 GUID。该字符串是以字符串形式存储在同步复制的“雇员”表中的 GUID。字段 s_GUID 是隐藏字段,该字段将添加到同步复制数据库中的每个同步复制表中。

Sub CheckGUIDType()

    Dim dbsConn As ADODB.Connection
    Dim rstEmployees As ADODB.Recordset

    ' Make a connection to the current database.
    Set dbsConn = Application.CurrentProject.Connection
    Set rstEmployees = New ADODB.Recordset
    rstEmployees.Open "Employees", dbsConn, , , adCmdTable

    ' Print the GUID to the immediate window.
    Debug.Print rst!s_GUID
    Debug.Print TypeName(rst!s_GUID)
    Debug.Print TypeName(GuidFromString(rst!s_GUID))

    Set rstEmployees = Nothing
    Set dbsConn = Nothing

End Sub