You can use the AfterUpdate event to encrypt, and the got focus event to decrypt. There's tons of code on the net, but here's a simple one that works. Just put it in a standard module:
The following function will work to both encrypt and decrypt a string:
Note :
Mid Function : Returns a Variant (String) containing a specified number of characters from a string.
Syntax : Mid(string, start[, length])
Mod Operator : Used to divide two numbers and return only the remainder.
Syntax : result = number1 Mod number2
Asc Function : Returns an Integer representing the character code corresponding to the first letter in a string.
Syntax : Asc(string)
Xor Operator : Used to perform a logical exclusion on two expressions.
Syntax : [result =] expression1 Xor expression2
Public Function Encrypt(ByVal strIn As String, ByVal strCode As String) As String
On Error GoTo Error_Handler
Dim i As Integer
Dim bytData As Byte
Dim bytKey As Byte
Dim strEncrypted As String
Encrypt = vbNullString
For i = 1 To Len(strIn)
bytData = Asc(Mid(strIn, i, 1))
bytKey = Asc(Mid(strCode, (i Mod Len(strCode)) + 1))
strEncrypted = strEncrypted & Chr(bytData Xor bytKey)
Next i
If strEncrypted <> vbNullString Then
Encrypt = strEncrypted
End If
Exit_Here:
Exit Function
Error_Handler:
Resume Exit_Here
End Function