'Here is a Class I use for Generating Guids
'Just Reference It and ask for GenerateGUID
Option Explicit
'Class Generates GUIDS
'DFW 07/25/00
Private Type Guid
Data1 As Long
Data2 As Long
Data3 As Long
Data4(8) As Byte
End Type
Private Declare Function CoCreateGuid _
Lib "ole32.dll" (pguid As Guid) As Long
Private Declare Function StringFromGUID2 Lib "ole32.dll" _
(rguid As Any, ByVal lpstrClsId As Long, _
ByVal cbMax As Long) As Long
'Gets the Computer name
Private Declare Function GetComputerName& Lib "kernel32" Alias "GetComputerNameA" (ByVal Buffer As String, nSize As Long)
Public Function GenerateGUID() As String
'***************************************************
'Purpose: Function to Generate GUID
'Author: David F. Wade
'Date: 07/25/00
Dim uGUID As Guid
Dim sGUID As String
Dim bGUID() As Byte
Dim lLen As Long
Dim RetVal As Long
lLen = 40
bGUID = String(lLen, 0)
CoCreateGuid uGUID
'Convert the structure into a displayable string
RetVal = StringFromGUID2(uGUID, VarPtr(bGUID(0)), lLen)
sGUID = bGUID
If (Asc(Mid$(sGUID, RetVal, 1)) = 0) Then RetVal = RetVal - 1
GenerateGUID = Left$(sGUID, RetVal)
End Function
Public Function GetGuid() As String
Dim strGUID As String
strGUID = GenerateGUID
strGUID = Mid(strGUID, 2, 36)
GetGuid = Replace(strGUID, "-", ""
End Function