
'*****************************************************************
' Code placed in the Form's "On Load" event
'*****************************************************************
Private Sub Form_Load()
Me!ctlLastVisit = "Unknown"  ' Set the control's default text

' Set the root key to "HKEY_LOCAL_MACHINE"
MyRegControl.hKey = regHkeyLocalMachine

' Set the subkey to examine
MyRegControl.Subkey = "Software\My Company\My Application\1.0"

If MyRegControl.ValueExists("LastVisit") Then
 Me!ctlLastVisit = MyRegControl.VALUES("LastVisit").Value
End If
End Sub

'*****************************************************************
' Code placed in the Close button's "On Click" event
'*****************************************************************
Private Sub ctlCloseButton_Click()
DoCmd.Close   ' Close the form
End Sub

'*****************************************************************
' Code placed in the Form's "On Close" event
'*****************************************************************
Private Sub Form_Close()

' Set the root key to "HKEY_LOCAL_MACHINE"
MyRegControl.hKey = regHkeyLocalMachine

' Set the initial subkey to "Software"
MyRegControl.Subkey = "Software"
'
' Check for our key. If it's not there, add it
'
If Not MyRegControl.KeyExists("My Company\My Application\1.0") Then
  MyRegControl.Keys.Add "My Company\My Application\1.0", ""
End If

' Set the subkey to modify
MyRegControl.Subkey = "Software\My Company\My Application\1.0"
'
' Check for our named value. If it's not there, add it
'
If Not MyRegControl.ValueExists("LastVisit") Then
  MyRegControl.VALUES.Add "LastVisit", regTypeSz, " "
End If
'
' Update the last visit date and time
'
MyRegControl.VALUES("LastVisit").Value = Format(Now, "dddddd ttttt")
DoCmd.Close  ' Close the form
End Sub


Figure 1:  The VBA code shown here belongs to the Welcome form shown in Figure 2 and demonstrates how to use the Wright Registry Control to read and write the Windows 95 registry. When the Welcome Form is opened the form's On Load event code displays the last date and time the form was used. The date and time value is updated in the registry
by code in the Close button's On Click event.

