GUID Generator - August 1997

At last month’s VB SIG meeting I asked for help creating GUID’s [Globally Unique Identifiers] using VB. Deborah Kurata, InStep Technologies, Inc, and others suggested that I look at GUIDGen, a utility that ships with C++. Thanks to that ‘lead’ I was able to create a VB 32-bit module that will generate GUID’s. The demo consists of one form and one module. This was my first tip-of-the-month. It is one of the most popular downloads.

2002/11/20 I created the function, CreateGUID, for VB.Net. GUID creation is a native VB.Net facility - but for compatibility purposes I created a VB.Net module that contains the CreateGUID function. See below to download the VB.Net version.

2005/12/18 I moved the VB6 code to a class module [cCreateGUID] and added several methods. See below for details.

2006/07/29 I converted the VB.Net version to VB 2005. Otherwise there were no changes.

VB6 Demo Program - Use cCreateGUID

GUID Generator Menu Items
VB Version

A table field in MSAccess can be defined with an ‘auto incremented’ data type. You could use a GUID instead. We are in the process of evaluating contact management software. One of the better ones is the Janna Contact Manager. While examining the Janna database I noted that the ID field in all tables uses a GUID. That makes sense. I plan to use a GUID as a record ID in applications I create in the future. In 1997 I wrote modCreateGUID to generate the GUID. In December 2005 I moved the code to a class module called 'cCreateGUID'. API ‘CoCreateGuid’ in library ‘ole32.dll’ does the work. You will, of course, need to make sure the user has ole32.dll installed with their Windows system. Use the Generate New GUID button to create a GUID and copy it to the clipboard. Use the File menu items to perform the described functions.

VB.Net Demo Program - Use modCreateGUID

VB.Net Version

Use modCreateGUID with VB.Net.

Updated 1999/12/13

I updated and simplified the code using API 'StringFromGUID2' to format the GUID. I found the code at Thanks to Ben Baird.

Updated 2001/10/26

The 'Copy to Clipboard' command did not copy the 'second' GUID to the clipboard. Fixed.

Updated 2005/12/18

The module code was moved to a class module [cCreateGUID]. The module code is still supported. Added methods: IsValidGUID, LenGUID, CreateGUIDWithPrefix. Added property bNoBraces to create a GUID without braces '{}'.

Download VB Code

Click here to download the VB Source Code [42k].
Click here to download the VB.Net Source Code [12k].
Click here to download the VB 2005 Source Code [13k].

Tip Index     Next Tip


Updated 2015/12/11