Add this to your module/form:
(NB: I don't have the declaration for "reg_binary" here, try reg_DWORD instead, or search the 'net for it).

VB Code:
  1. Public Enum Reg_HKey_Area         'Constants for specifying areas
  2.   HKEY_CLASSES_ROOT = &H80000000
  3.   HKEY_CURRENT_USER = &H80000001
  4.   HKEY_LOCAL_MACHINE = &H80000002
  5.   HKEY_USERS = &H80000003
  6. End Enum
  7.  
  8. Const ERROR_NONE = 0   'Function results (if specified in the function)
  9. Const ERROR_BADDB = 1
  10. Const ERROR_BADKEY = 2
  11. Const ERROR_CANTOPEN = 3
  12. Const ERROR_CANTREAD = 4
  13. Const ERROR_CANTWRITE = 5
  14. Const ERROR_OUTOFMEMORY = 6
  15. Const ERROR_ARENA_TRASHED = 7
  16. Const ERROR_ACCESS_DENIED = 8
  17. Const ERROR_INVALID_PARAMETERS = 87
  18. Const ERROR_NO_MORE_ITEMS = 259
  19. Const ERROR_INSUFFICIENT_BUFFER = 122
  20. Const ERROR_KEY_DELETED = 1018
  21. Const ERROR_REGISTRY_CORRUPT = 1015
  22.  
  23. Public Enum Reg_Data_Type         'Constants for specifying data types
  24.   Reg_String = &O1
  25.   Reg_Dword = &O4
  26. End Enum
  27.  
  28. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  29. Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
  30.    ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  31. Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
  32.    ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
  33. Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
  34.    ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
  35.  
  36.  
  37.  
  38. Function Reg_SetKeyValue(KeyArea As Reg_HKey_Area, sKeyName As String, sValueName As String, vValue As Variant, Optional lValueType As Reg_Data_Type)
  39. 'Sets a specified value in the registry (may or may not exist already).
  40.  
  41. 'NB:  This will only work if the KEY exists.  To ensure it does
  42. '     you can simply call Reg_CreateNewKey (which creates it if
  43. '     necessary) or Reg_CheckKeyExists.
  44.  
  45. 'Returns codes as listed in DECLARATIONS (ie: 0=error_none = no error)
  46. Dim lRetVal As Long, hKey As Long
  47.  
  48.             'try to detect type!
  49.     If lValueType <> Reg_String And lValueType <> Reg_Dword Then
  50.       lValueType = Reg_String
  51.       If (IsNumeric(vValue)) Then
  52.         If CInt(vValue) = vValue Then lValueType = Reg_Dword
  53.       End If
  54.     End If
  55.                                     'open the specified key
  56.     lRetVal = RegOpenKeyEx(KeyArea, sKeyName, 0, KEY_ALL_ACCESS, hKey)
  57.     If lRetVal <> ERROR_NONE Then Reg_SetKeyValue = lRetVal: Exit Function
  58.    
  59.     Select Case lValueType          'set the value
  60.     Case Reg_String:   Reg_SetKeyValue = RegSetValueExString(hKey, sValueName, 0&, Reg_String, CStr(vValue & Chr$(0)), CLng(Len(vValue) + 1))
  61.     Case Reg_Dword:    Reg_SetKeyValue = RegSetValueExLong(hKey, sValueName, 0&, Reg_Dword, CLng(vValue), 4)
  62.     End Select
  63.  
  64.     RegCloseKey (hKey)              'close the key
  65.  
  66. End Function