GUIDFromString 函式會將字串轉換成 GUID,這是 Byte 類型的陣列。
語法
GUIDFromString (stringexpression)
必要的 stringexpression 引數是字串運算式,其會以字串形式評估為 GUID。
註解
Microsoft Access 資料庫引擎會將 GUID 儲存為 Byte 類型的陣列。 不過,Access 無法從表單或報表上的控制項傳回 位元組 資料。 若要從控制項傳回 GUID 的值,您必須將它轉換成字串。 若要將 GUID 轉換成字串,請使用 StringFromGUID 函數。 若要將字串轉換成 GUID,請使用 GUIDFromString 函數。
查詢範例
| 運算式 | 結果 |
|---|---|
| SELECT userID,GUIDfromString (userGUID) as GUIDCode FROM GUID_Table; | 顯示 “userID”,將 StringExpression (userGUID) 轉換為 GUID () 位元組陣列,並顯示在 GUIDCode 行中。 此範例僅適用於可評估為 GUID 的字串運算式。 |
VBA 範例
注意
下列範例示範如何在 Visual Basic for Applications (VBA) 模組中使用此函數。 如需使用 VBA 的詳細資訊,請在 [搜尋] 旁的下拉式清單中選取 [開發人員參考],並在 [搜尋] 方塊中輸入一個或多個字詞。
下列範例使用 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