Hi, Bob.
It's not my application. The credit goes to Danny Lesandrini of DataFast
Consulting.
When I use <Danny's> MDB and enter in the values as listed
above and clidk the "Query Value Key" button, I receive a message box
"Could
not open key".
When I tested this application, it worked fine. That was years ago and
probably on a Windows ME computer. After testing this afternoon, I can see
that his code will not work on Windows XP (and likely not Windows 2K,
either). Fortunately, I see what the problem is.
Danny's code in the CommandFunctions( ) subroutine of the form is
concatening "SOFTWARE\" to the subkey string before it is passed to the
Windows API function. This altered subkey's name doesn't exist, so the
Windows API can't find it and open it for you. You need to change all
occurrences in his code to remove this concatenated string. For example,
change:
txtValue = ReadRegValue(HKEY_LOCAL_MACHINE, _
"SOFTWARE\" & txtSubKey, txtValueName)
to:
txtValue = ReadRegValue(HKEY_LOCAL_MACHINE, _
txtSubKey, txtValueName)
But that's not the only problem. Danny's code is based upon the following
Microsoft KB article:
http://support.microsoft.com/default.aspx?id=145679
If you read the information in this article, you'll notice that it only
handles REG_SZ and REG_DWORD key sizes (if you didn't already catch this
limitation by reading Danny's code). These functions don't handle the
Windows Registry key for the Environment Path key size, which is
REG_EXPAND_SZ, a Unicode NULL-terminated string. I searched through the
Microsoft KB on how to read a REG_EXPAND_SZ subkey and only found this
Microsoft KB article:
http://support.microsoft.com/default.aspx?id=265331
Unfortunately, the example code is written for Visual Fox Pro, so it won't
work in VBA. But the example code shows that the string passed to the
Windows API function needs to be sized to the length of the key's value and
filled with spaces, so you'll need to add the following code to the
bas_E-Zone_Reg module:
In the module's Declarations section, add:
Public Const REG_EXPAND_SZ = 2
In the ReadRegValue( ) function's "Select Case lType" block, add the
following Case statement:
Case REG_EXPAND_SZ
sValue = Space(lcch)
lrc = RegQueryValueExSTRING(hKeyHandle, _
sValueName, 0&, lType, sValue, lcch)
ReadRegValue = Left(sValue, lcch - 1)
Save and compile the code and run the application to query this subkey's
value again. It should work now.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)